Beispiel #1
0
 private void responsePing()
 {
     try
     {
         byte[] packet_ping = new byte[0];
         if (ServerData.CustomMOTD)
         {
             string dataStr   = "{\"description\":\"" + ServerData.ServerName + "\",\"players\":{\"max\":1,\"online\":0},\"version\":{\"name\":\"TEST\",\"protocol\":5}}";
             byte[] packet_id = getVarInt(0);
             packet_ping = concatBytes(packet_id, getString(dataStr));
         }
         else
         {
             var tmp = new ProtocolConnection(new TcpClient());
             tmp.doPing(Lobby.Host, Lobby.Port, ref packet_ping);
         }
         Client.Client.Send(concatBytes(getVarInt(packet_ping.Length), packet_ping));
         byte[] response = readDataRAW(readNextVarIntRAW());
         Client.Client.Send(concatBytes(getVarInt(response.Length), response));
     }
     finally
     {
         Close();
     }
 }
Beispiel #2
0
        public void OnConnectionLost(Conn.DisconnectReason reason, string message)
        {
            switch (reason)
            {
            case Conn.DisconnectReason.ConnectionLost:
                if (trans_server)
                {
                    if (this.Proxy != null)
                    {
                        this.Proxy.Dispose();
                        this.Proxy = null;
                        return;
                    }
                }
                break;

            case Conn.DisconnectReason.InGameKick:
                SendPacket(PacketIncomingType.KickPacket, getString(message));
                break;

            case Conn.DisconnectReason.LoginRejected:
                if (!login_phase)
                {
                    SendPacket(PacketIncomingType.ChatMessage, getString(message));
                }
                else
                {
                    SendPacket(0x00, getString(message));
                }
                break;
            }
            Debug.Log("Connection Lost: " + message, Username);
            this.Close();
        }
Beispiel #3
0
 private async void CreateProxyBridge(Data.Servers.Server server)
 {
     if (this.Client.Connected)
     {
         await Task.Run(() =>
         {
             TcpClient remote = new TcpClient();
             try
             {
                 remote.Connect(server.Host, server.Port);
                 if (remote.Connected)
                 {
                     ProtocolConnection tmp = new ProtocolConnection(remote, server.Protocol, this);
                     if (tmp.Login(server))
                     {
                         if (Proxy != null)
                         {
                             Proxy.Dispose();
                         }
                         Proxy = tmp;
                         if (cRead == null || !cRead.IsAlive)
                         {
                             handlePacket();
                         }
                     }
                     else
                     {
                         tmp.Dispose();
                     }
                 }
             }
             catch (Exception e)
             {
                 Debug.Log(e.Message, "Exception");
                 if (trans_server)
                 {
                     SendMessage(string.Format(ServerData.MsgConnectFailed, e.Message));
                 }
                 else
                 {
                     this.Close();
                 }
             }
         });
     }
 }