Ejemplo n.º 1
0
        private void ThreadConnectToServer(ModThreadHelper.Info ti)
        {
            ClientMessages(string.Format("ModInterface: Started connection thread. Connecting to {0}:{1}", this.gameServerIp, this.gameServerPort));
            while (!ti.eventRunning.WaitOne(0))
            {
                if (client == null)
                {
                    try
                    {
                        TcpClient tcpClient = new TcpClient(this.gameServerIp, this.gameServerPort);
                        tcpClient.ReceiveBufferSize = 10 * 1024 * 1024;
                        tcpClient.SendBufferSize    = 10 * 1024 * 1024;

                        client = new ModProtocol(tcpClient, PackageReceivedDelegate, DisconnectedDelegate);
                        ClientMessages("ModInterface: Connected with " + client + " over port " + this.gameServerPort);

                        OnConnected?.Invoke();
                    }
                    catch (SocketException)
                    {
                        // Ignore
                    }
                    catch (Exception e)
                    {
                        ClientMessages(e.GetType() + ": " + e.Message);
                        client = null;
                    }
                }
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 2
0
 public void Disconnect()
 {
     if (client != null)
     {
         client.Close();
         client = null;
     }
 }
Ejemplo n.º 3
0
        public void Send(CmdId cmdId, ushort seqNr, object data)
        {
            //ClientMessages("Sending request event: c=" + cmdId + " sNr=" + seqNr + " d=" + data + " client="+client);
            // Send events of the network
            ModProtocol c = client;

            if (c != null)
            {
                ModProtocol.Package p = new ModProtocol.Package(cmdId, clientId, seqNr, data);
                c.AddToSendQueue(p);
            }
        }
Ejemplo n.º 4
0
 // Called in a thread!
 private void DisconnectedDelegate(ModProtocol prot)
 {
     ClientMessages("DisconnectedDelegate called");
     Disconnect();
 }
Ejemplo n.º 5
0
 // Called in a thread!
 private void PackageReceivedDelegate(ModProtocol con, ModProtocol.Package p)
 {
     GameEventReceived(p);
 }