Skip to content

Commit 3962936

Browse files
committed
Init
1 parent 516d458 commit 3962936

32 files changed

+773
-0
lines changed

.vs/Server/v14/.suo

58.5 KB
Binary file not shown.

.vs/Server/v15/.suo

71 KB
Binary file not shown.

.vs/Server/v15/Server/sqlite3/db.lock

Whitespace-only changes.
448 KB
Binary file not shown.
32 KB
Binary file not shown.
3.94 MB
Binary file not shown.

Server.sln

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25123.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{333004B4-577A-489F-916D-A5DE468636E0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{333004B4-577A-489F-916D-A5DE468636E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{333004B4-577A-489F-916D-A5DE468636E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{333004B4-577A-489F-916D-A5DE468636E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{333004B4-577A-489F-916D-A5DE468636E0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Server/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
5+
</startup>
6+
</configuration>

Server/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Server")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Server")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("333004b4-577a-489f-916d-a5de468636e0")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Server/Script/Program.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Threading;
7+
using System.Net.Sockets;
8+
using System.Net;
9+
10+
namespace Server
11+
{
12+
class Program
13+
{
14+
static void Main(string[] args)
15+
{
16+
Server server = new Server(10000); //!< 포트 번호
17+
18+
while(true)
19+
{
20+
Thread.Sleep(1);
21+
}
22+
}
23+
}
24+
}

Server/Script/RoomInfo.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace INFO
4+
{
5+
class Room
6+
{
7+
public bool isPlaying = false; // 게임
8+
9+
public byte nowUser { get; set; } // 방에 들어와 있는 유저 수
10+
public byte limitUser; // 인원 한계
11+
12+
public int roomIdx; // 방 번호
13+
public string roomName; // 방 이름
14+
public string roomPW; // 방 비번
15+
}
16+
}

Server/Script/Server.cs

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Threading;
7+
using System.Net;
8+
using System.Net.Sockets;
9+
10+
namespace Server
11+
{
12+
class Server
13+
{
14+
public static List<User> v_user = new List<User>();
15+
public static List<INFO.Room> v_rooms = new List<INFO.Room>();
16+
public static ManualResetEvent allDone = new ManualResetEvent(false);
17+
public static int roomCount;
18+
19+
/**
20+
* @brief 초기화
21+
* @port 포트번호
22+
*/
23+
public Server(int port)
24+
{
25+
v_rooms.Clear();
26+
v_user.Clear();
27+
roomCount = 0;
28+
WaitingSocket(port);
29+
}
30+
31+
/**
32+
* @brief 유저 제거
33+
* @target 제거 대상
34+
*/
35+
public static void RemoveUser(User target)
36+
{
37+
v_user.Remove(target);
38+
Console.WriteLine(string.Format("n(User) : {0}", v_user.Count));
39+
}
40+
41+
/**
42+
* @brief 클라이언트의 소켓 접속 대기
43+
* @part 포트 번호
44+
*/
45+
public static void WaitingSocket(int port)
46+
{
47+
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);
48+
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
49+
listener.NoDelay = true;
50+
listener.LingerState = new LingerOption(true, 0);
51+
listener.SendBufferSize = 81920; //!< 때에 맞게 맞추어 사용할 것
52+
listener.ReceiveBufferSize = 81920; //!< 때에 맞게 맞추어 사용할 것
53+
54+
try
55+
{
56+
listener.Bind(localEndPoint);
57+
listener.Listen(100);
58+
Console.WriteLine("Waiting For A Connection...");
59+
60+
while(true)
61+
{
62+
allDone.Reset();
63+
listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
64+
allDone.WaitOne();
65+
}
66+
}
67+
catch (Exception e)
68+
{
69+
Console.WriteLine(e.ToString());
70+
}
71+
72+
Console.WriteLine("\n\nPress ENTER to continue...");
73+
Console.Read();
74+
}
75+
76+
/**
77+
* @brief 클라이언트가 접속에 성공한 경우 호출되는 콜백 함수
78+
* @result 결과
79+
*/
80+
static void AcceptCallback(IAsyncResult result)
81+
{
82+
allDone.Set();
83+
84+
Socket listener = (Socket)result.AsyncState;
85+
Socket handler = listener.EndAccept(result);
86+
handler.NoDelay = true;
87+
handler.LingerState = new LingerOption(true, 0);
88+
handler.SendBufferSize = 81920;
89+
handler.ReceiveBufferSize = 81920;
90+
91+
v_user.Add(new User(handler));
92+
Console.WriteLine(string.Format("n(User) : {0}", v_user.Count));
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)