public GameServer(PlayPage playpage, string name, string portUDP1, string portUDP2, string portTCP1L, string portTCP1S, string portTCP2L, string portTCP2S, string portTCP3L, string portTCP3S) { serverBussyflag = false; this.playpage = playpage; gameData = new GameData(); serverUDP = new UDPListener(playpage, name, portUDP1, portUDP2); firstConnectionClient = TCPClientRemote.Instance; firstConnectionClient.initTCPClient(playpage, name); firstConnectionClient.initListener(portTCP3L); firstConnectionClient.Received += firstConnectionReceived; this.portTCP3S = portTCP3S; this.portTCP2S = portTCP2S; this.portTCP1L = portTCP1L; server = new Server(playpage, portTCP2S); server.Received1 += onServerRecieved1; server.Received2 += onServerRecieved2; client = TCPClientRemote.Instance; client.initTCPClient(playpage, name); client.Received += OnReceived1; server.addForPlayer1Listener(portTCP1L); client.initListener(portTCP1S); server.addForPlayer2Listener(portTCP2L); client.initSender(portTCP1L, IPAdress.LocalIPAddress()); server.addForPlayer1Sender(portTCP1S, IPAdress.LocalIPAddress()); server.addForPlayer2Listener(portTCP2L); }
// TCP first connection private void firstConnectionReceived(string remoteMessage, string remoteAdress, string remotePort) { if (serverBussyflag) { firstConnectionClient.initSender(portTCP3S, remoteAdress); firstConnectionClient.SendRequest("Cancel server bussy"); } else { if (firstConnectionClient.name.Equals(remoteMessage.Split('\r')[0])) { playpage.DisplayMessages("Check name: this same names"); firstConnectionClient.initSender(portTCP3S, remoteAdress); firstConnectionClient.SendRequest("Cancel this same name"); } else { playpage.DisplayMessages("Check name: different name"); playpage.AddClient(remoteMessage.Split('\r')[0] + " " + remoteAdress + " " + remotePort); } } }
public void addForPlayer2Sender(string portSender, string remoteAdress) { Client2.initSender(portSender, remoteAdress); }