public override void OnDisconnected(EndPoint endPoint) { SessionManager.Instance.Remove(this); GameRoom room = RoomManager.Instance.Find(1); room.Push(room.LeaveGame, MyPlayer.Info.ObjectId); Console.WriteLine($"OnDisconnected : {endPoint}"); }
public override void OnDisconnected(EndPoint endPoint) { SessionManager.Instance.Remove(this); if (Room != null) { GameRoom room = Room; Room.Push(() => room.Leave(this)); Room = null; } Console.WriteLine($"OnDisconnected : {endPoint}"); }
public override void OnDisConnected(EndPoint endPoint) { SessionManager.Instance.Remove(this); if (Room != null) { GameRoom room = Room; // 이렇게 함으로 인해 잡큐에 작업자가 Room이 null이 되도 room에 있는 정보로 보기때문에 문제 되지않음. room.Push(() => room.Leave(this)); Room = null; } Console.WriteLine($"OnDisConnected : {endPoint}"); }
static void TickRoom(GameRoom room, int tick = 100) { var timer = new System.Timers.Timer(); timer.Interval = tick; timer.Elapsed += ((s, e) => { room.Update(); }); timer.AutoReset = true; timer.Enabled = true; _timers.Add(timer); }
// Main 함수에서 While 안에 Update 돌릴때와 다른 점은 // 이제 update 작업을 main 함수를 작업하는 쓰레드만 하는게 아니라 // 다른 쓰레드들도 update 작업에 동원 될 수 있다. static void TickRoom(GameRoom room, int tick = 1000) { var timer = new System.Timers.Timer(); timer.Interval = tick; // 몇(ms)마다 반복할지 timer.Elapsed += (s, e) => { room.Update(); }; // 반복할 작업 timer.AutoReset = true; // 작업 후 재실행 여부 timer.Enabled = true; // 실행 _timers.Add(timer); // 나중에 끄고싶을수도 있으니 // timer.Stop(); }
public override void OnDisconnected(EndPoint endPoint) { SessionManager.Instance.Remove(this); if (Room != null) { GameRoom room = Room; room.Push(() => room.Leave(this)); Room = null; } IPEndPoint ipEndPoint = endPoint as IPEndPoint; Console.WriteLine($"OnDisconnected: {ipEndPoint.Address}:{ipEndPoint.Port}"); }
public override void OnDisconnected(EndPoint endPoint) { GameLogic.Instance.Push(() => { if (MyPlayer != null) { return; } GameRoom room = GameLogic.Instance.Find(1); room.Push(room.LeaveGame, MyPlayer.Info.ObjectId); }); SessionManager.Instance.Remove(this); }
public override void OnDisconnected(EndPoint endPoint) { SessionManager.Instance.Remove(this); if (Room != null) { // * 수정된 부분 // 이제 Leave를 바로 실행하지 않고, 해야 할 작업으로 JobQueue에 넘겨준다. // GameRoom을 별고로 선언, Room을 저장해둬서 클라이언트가 종료되어도 참조 카운트가 유지되게 한다. // (그렇지 않으면 클라 종료 후 Room이 null이 되어 JobQueue에서 작업을 처리하려 할 때 크래시가 난다) GameRoom room = Room; room.Push(() => room.Leave(this)); Room = null; } Console.WriteLine($"{endPoint}의 접속이 종료되었습니다."); }
public override void OnDisconnected(EndPoint endPoint) { // TEMP 1번룸만 존재 //RoomManager.Instance.Find(1).LeaveGame(MyPlayer.Info.ObjectId); GameLogic.Instance.Push(() => { if (MyPlayer == null) { return; } GameRoom room = GameLogic.Instance.Find(1); room.Push(room.LeaveGame, MyPlayer.Info.ObjectId); }); SessionManager.Instance.Remove(this); //Console.WriteLine($"OnDisconnected : {endPoint}"); }
static void Main(string[] args) { ConfigManager.LoadConfig(); DataManager.LoadData(); GameLogic.Instance.Push(() => { GameRoom room = GameLogic.Instance.Add(1); }); // DNS (Domain Name System) string host = Dns.GetHostName(); IPHostEntry ipHost = Dns.GetHostEntry(host); IPAddress ipAddr = ipHost.AddressList[1]; IPEndPoint endPoint = new IPEndPoint(ipAddr, Port); IpAddress = ipAddr.ToString(); _listener.Init(endPoint, () => { return(SessionManager.Instance.Generate()); }); Console.WriteLine("Listening....."); StartServerInfoTask(); // GameLogicTask { Thread t = new Thread(DbTask); t.Name = "DB"; t.Start(); } // NetworkTask { Thread t = new Thread(NetworkTask); t.Name = "Network Send"; t.Start(); } // DBTask Thread.CurrentThread.Name = "GameLogic"; GameLogicTask(); }
static void Main(string[] args) { // Select the map int selectedMap = 0; string[] mapFiles = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/../../../../Maps"); ConsoleKey key; do { Console.Clear(); for (int i = 0; i < mapFiles.Length; i++) { Console.WriteLine("[{0}] {1}", i == selectedMap ? "X" : " ", Path.GetFileNameWithoutExtension(mapFiles[i])); } key = Console.ReadKey().Key; if (key == ConsoleKey.UpArrow && selectedMap > 0) { selectedMap--; } else if (key == ConsoleKey.DownArrow && selectedMap < mapFiles.Length) { selectedMap++; } }while (key != ConsoleKey.Enter); // Load the map var map = new TileMap(); map.LoadMap(mapFiles[selectedMap]); Room = new GameRoom(map); Console.WriteLine("MAP LOADED"); Timer.Start(); server = new WebSocketServer(IPAddress.Any, 1337); server.AddWebSocketService <GameService>("/"); server.Start(); Console.ReadKey(true); server.Stop(); Console.WriteLine("SERVER STOPPED"); }
static void Main(string[] args) { ConfigManager.LoadConfig(); // 설정파일 읽어오기 DataManager.LoadData(); // 설정파일에 맞춰 데이터 불러오기 // DB Test using (AppDbContext db = new AppDbContext()) { db.Accounts.Add(new AccountDb() { AccountName = "TestAccount" }); db.SaveChanges(); } GameRoom room = RoomManager.Instance.Add(1); // 서버 시작할때 일단 게임룸 하나 추가, 맵 번호는 1번이라 가정 TickRoom(room, 50); // 생성된 room의 update가 50ms마다 한번씩 실행되도록 한다. // DNS (Domain Name System) string host = Dns.GetHostName(); IPHostEntry ipHost = Dns.GetHostEntry(host); IPAddress ipAddr = ipHost.AddressList[0]; IPEndPoint endPoint = new IPEndPoint(ipAddr, 7777); _listener.Init(endPoint, () => { return(SessionManager.Instance.Generate()); }); Console.WriteLine("Listening..."); //FlushRoom(); //JobTimer.Instance.Push(FlushRoom); // 이렇게 메인 루프 어딘가에서 콘텐츠들을 전부 업댓 시켜주는 코드가 있어야 한다. // 이걸 어디서 놓고 돌릴지 매우 햇갈림 while (true) { //JobTimer.Instance.Flush(); //GameRoom room = RoomManager.Instance.Find(1); //room.Push(room.Update); Thread.Sleep(100); } }
static void Main(string[] args) { var config = new NetPeerConfiguration("application name") { Port = 12345 }; var server = new NetServer(config); server.Start(); // server NetIncomingMessage msg; GameRoom newGameRoom = new GameRoom(null, "TEST", 8); NetworkSessionContainer.NetworkSessions.GameRooms.Add(newGameRoom); while (true) { //Ustawić odświerzanie co 16.666ms foreach (GameRoom gameRoom in NetworkSessionContainer.NetworkSessions.GameRooms) { gameRoom.Update(); } if ((msg = server.ReadMessage()) == null) { continue; } switch (msg.MessageType) { case NetIncomingMessageType.ConnectionApproval: { Console.WriteLine("Connected"); break; } case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.StatusChanged: { NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); break; } case NetIncomingMessageType.Data: { short opcode = msg.ReadInt16(); if (opcode == 2000) //Logowanie użytkownika { unsafe { if (!NetworkSessionContainer.NetworkSessions.UserSessions.Exists(x => x.Connection == msg.SenderConnection)) { UserSession session = new UserSession(); TypedReference tr = __makeref(session); IntPtr ptr = **(IntPtr **)(&tr); Console.WriteLine(ptr); session.Connection = msg.SenderConnection; Random randID = new Random(); session.ID = randID.Next(1000000); //martwić sie tym będe później //session.ID = ptr.ToInt32(); session.Name = msg.ReadString(); NetOutgoingMessage outMessage = session.Connection.Peer.CreateMessage(); outMessage.Write((short)2000); outMessage.Write(session.ID); session.Connection.SendMessage(outMessage, NetDeliveryMethod.UnreliableSequenced, outMessage.LengthBytes); session.UserGameState = new MenuState(); NetworkSessionContainer.NetworkSessions.UserSessions.Add(session); // Musze dorobić jakąś obsługe menu } else { //Zaimplementować że jest już taki gość } //TO NIE SPAWN A LOGIN /*foreach (UserSession otherPlayers in UsersSessions.Sessions) * { * NetOutgoingMessage informAboutPlayer = session.Connection.Peer.CreateMessage(); * informAboutPlayer.Write((short)2620); * informAboutPlayer.Write(otherPlayers.ID, 32); * informAboutPlayer.Write("konserwa"); * session.Connection.SendMessage(informAboutPlayer, NetDeliveryMethod.UnreliableSequenced, informAboutPlayer.LengthBytes); * Console.WriteLine($"Wysyłam pakiet od {session.ID} wysyłam dane o {otherPlayers.ID}"); * //Console.WriteLine(BitConverter.ToString(informAboutPlayer.Data)); * * * NetOutgoingMessage SendToCurrentPlayerAboutPlayers = otherPlayers.Connection.Peer.CreateMessage(); * SendToCurrentPlayerAboutPlayers.Write((short)2620); * SendToCurrentPlayerAboutPlayers.Write(session.ID, 32); * SendToCurrentPlayerAboutPlayers.Write("konserwa"); * otherPlayers.Connection.SendMessage(SendToCurrentPlayerAboutPlayers, NetDeliveryMethod.UnreliableSequenced, SendToCurrentPlayerAboutPlayers.LengthBytes); * Console.WriteLine($"Wysyłam pakiet od {otherPlayers.ID} wysyłam dane o {session.ID}"); * // Console.WriteLine(BitConverter.ToString(SendToCurrentPlayerAboutPlayers.Data)); * }*/ } } else { // NetworkSessionContainer.NetworkSessions.UserSessions.Find(x => x.Connection == msg.SenderConnection).UserGameState.Recive(msg); foreach (UserSession user in NetworkSessionContainer.NetworkSessions.UserSessions) { if (user.Connection == msg.SenderConnection) { user.UserGameState.Recive(msg); } } } break; } case NetIncomingMessageType.ErrorMessage: Console.WriteLine(msg.ReadString()); break; default: { Console.WriteLine("Unhandled type: " + msg.MessageType); break; } } //server.Recycle(msg); } }
public Player(string id, GameRoom room) { Room = room; ID = id; Entity = new PlayerEntity(this, room); }
public GameService() { Room = Program.Room; }
public Broadcast(GameRoom room, ClientSession session, string chat) { _room = room; _session = session; _chat = chat; }