public StringPacket MakeStringPacket(string s) { StringPacket packet = new StringPacket { SendDate = DateTime.UtcNow, String = s }; return(packet); }
public void RecieveClientMessage(ServerConnection client, BasePacket recievedPacket) { switch ((MessageType)recievedPacket.MessageType) { case MessageType.WR_ClientRequest_LeaveRoom: { StringPacket leavePacket = (StringPacket)recievedPacket; client.SendPacketToClient(NetworkPacketFactory.Instance.MakeStringPacket(leavePacket.String), MessageType.WR_ServerResponse_SuccessLeaveRoom); RemoveClient(client); Logger.Instance.Info(client.Name + " left " + RoomName); break; } case MessageType.GR_ClientRequest_Ready: { // Can this request fail? client.SendPacketToClient(new BasePacket(), MessageType.GR_ServerResponse_SuccessReady); _clientReadyStatus[client] = true; Logger.Instance.Info(client.Name + " readied up in " + RoomName + ". (" + GetReadyCount() + "/" + ComponentClients.Count + ") players ready"); if (GetReadyCount() == ComponentClients.Count) { // TODO: Introduce a countdown here LaunchGameInstance(); Logger.Instance.Info(RoomName + " has started a game instance"); } OnRoomStateChanged(); break; } case MessageType.GR_ClientRequest_Unready: { client.SendPacketToClient(new BasePacket(), MessageType.GR_ServerResponse_SuccessUnready); _clientReadyStatus[client] = false; Logger.Instance.Info(client.Name + " unreadied in " + RoomName + ". (" + GetReadyCount() + "/" + ComponentClients.Count + ") players ready"); OnRoomStateChanged(); break; } } }
public void RecieveServerResponse(BasePacket recievedPacket) { switch ((MessageType)recievedPacket.MessageType) { case MessageType.WR_ServerSend_WaitingRoomFullInfo: var waitingRooms = (WaitingRoomInformation)recievedPacket; Client_OnWaitingRoomInformationRecieved(waitingRooms); break; case MessageType.WR_ServerResponse_FailJoinRoom: Console.WriteLine("FAILED TO JOIN ROOM"); break; case MessageType.WR_ServerResponse_FailCreateRoom: Console.WriteLine("FAILED TO CREATE ROOM"); break; case MessageType.WR_ServerResponse_SuccessJoinRoom: { StringPacket lobbyID = (StringPacket)recievedPacket; ClientMessageReciever_OnRoomSuccessfullyJoined(lobbyID.String); break; } case MessageType.WR_ServerResponse_SuccessLeaveRoom: { StringPacket lobbyID = (StringPacket)recievedPacket; ClientMessageReciever_OnRoomSuccessfullyLeft(lobbyID.String); break; } case MessageType.GR_ServerResponse_SuccessReady: { ClientMessenger_OnRoomSuccessfullyReady(); break; } case MessageType.GR_ServerResponse_SuccessUnready: { ClientMessenger_OnRoomSuccessfullyUnready(); break; } } }
public void RecieveClientMessage(ServerConnection client, BasePacket recievedPacket) { switch ((MessageType)recievedPacket.MessageType) { case MessageType.WR_ClientRequest_WaitingRoomInfo: { client.SendPacketToClient(GetWaitingRoomInformation(), MessageType.WR_ServerSend_WaitingRoomFullInfo); break; } case MessageType.WR_ClientRequest_CreateRoom: { if (_activeRooms.Count < Server.MAX_ROOMS) { Logger.Instance.Info("New Game Room created by " + client.Name); CreateNewRoom(client.Name + "'s Room"); GameRoom_OnRoomStateChanged(); } else { client.SendPacketToClient(new BasePacket(), MessageType.WR_ServerResponse_FailCreateRoom); } break; } case MessageType.WR_ClientRequest_JoinRoom: { StringPacket joinPacket = (StringPacket)recievedPacket; GameRoom joinedRoom = GetGameRoomFromID(joinPacket.String); if (joinedRoom.ComponentClients.Count < MAX_PEOPLE_PER_ROOM) { client.SendPacketToClient(NetworkPacketFactory.Instance.MakeStringPacket(joinPacket.String), MessageType.WR_ServerResponse_SuccessJoinRoom); joinedRoom.AddClientToRoom(client); GameRoom_OnRoomStateChanged(); Logger.Instance.Info(client.Name + " joined " + joinedRoom.RoomName); } else { client.SendPacketToClient(new BasePacket(), MessageType.WR_ServerResponse_FailJoinRoom); } break; } } }