private async Task <NetworkPacket> ProcessRequest(StreamSocket socket, NetworkPacket packet) { AcknowledgePacket acknowledgement = new AcknowledgePacket(); if (packet.Type == PacketType.LobbyCommand) { LobbyCommandPacket command = packet as LobbyCommandPacket; if (command.Command == LobbyCommands.SetupGame) { string hostID = command.PlayerID; GameData game = _gameList[_playerList[hostID].GameID]; await GamePage.gameInstance.StartServer(hostID, _playerList, game); } else { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { OnLobbyCommand(command); }); } } else if (packet.Type == PacketType.LobbyData) { LobbyData lobbyData = packet as LobbyData; _playerList = lobbyData._playerList; _gameList = lobbyData._gameList; OnLobbyUpdated("playerList"); OnLobbyUpdated("gamesList"); } return(acknowledgement); }
private async Task <NetworkPacket> HandleRequest(StreamSocket socket, NetworkPacket packet) { AcknowledgePacket acknowledgement = new AcknowledgePacket(); if (packet != null) { if (packet.Type == PacketType.Salutation) { SalutationPacket salutation = packet as SalutationPacket; await HandlePlayerConnection(socket, salutation); } } return(acknowledgement); }
private static void ProcessSalutation(NetworkPacket packet) { if (NetworkInterface.IsHost) { SalutationPacket salutation = packet as SalutationPacket; AcknowledgePacket ack = new AcknowledgePacket(salutation.Name, salutation.Timestamp); ack.Response = DetermineAppropriateResponse(salutation); if (ack.Response == AcknowledgePacket.Acknowledgement.OK) { AddNewGamer(salutation); } NetworkInterface.SendPacket(packet.SourceIP, ack); } }
private static void ProcessAcknowledge(NetworkPacket packet) { // TODO: work on the joining stuff AcknowledgePacket ack = packet as AcknowledgePacket; if (ack.Response == AcknowledgePacket.Acknowledgement.OK) { ConnectionID = ack.Name; } else if (ack.Response == AcknowledgePacket.Acknowledgement.DuplicateName) { string newID = ack.Name + GameModel.Random.Next(0, 10); SalutationPacket newSalutation = new SalutationPacket(newID); SendToHost(newSalutation); } }