private void ConnectInfoResponse(byte[] bytes, IPEndPoint refEp) { //send ack ConnectInfo conv = ConversationFactory.Instance .CreateFromMessage <ConnectInfo>(bytes, refEp, null, null, null); conv.Start(); //connect to server ConnectMsg msg = Message.Decode <ConnectMsg>(bytes); gameServer = msg.GameServer; //open tcp connection TCPClient tcp = new TCPClient(); tcp.SetupConnection(); int gamePort = tcp.port; tcpClients.Add(tcp); //send message with info on which port ConnectGameServer connectConv = ConversationFactory.Instance .CreateFromConversationType <ConnectGameServer> (gameServer, null, null, null); connectConv._GameId = 1; connectConv._NumPlayers = 1; connectConv._Port = gamePort; connectConv.Start(); }
public void ConnectGameServerResponse(byte[] bytes, IPEndPoint refEp) { ConnectGameServer conv = ConversationFactory.Instance. CreateFromMessage <ConnectGameServer>(bytes, refEp, null, null, null); conv.Start(); ConnectGSMsg convMessage = Message.Decode <ConnectGSMsg>(bytes); //generate TCP client TCPClient client = new TCPClient(); IPEndPoint clientTcp = refEp; clientTcp.Port = convMessage.Port; client.ConnectToServer(clientTcp); int playerId = convMessage.PlayerId; //need to store client tcp somewhere tcpClients.Add(playerId, client); //add player to game Game game; //find game in list if (gameList.Exists(x => x.gameId == convMessage.GameId)) { game = gameList.Find(x => x.gameId == convMessage.GameId); } else { game = new Game(convMessage.GameId, convMessage.Players, SendCard); } game.AddPlayer(playerId); }