Exemplo n.º 1
0
    public static void Welcome(GameServer.Packet _packet)
    {
        string _msg  = _packet.ReadString();
        int    _myId = _packet.ReadInt();

        Debug.Log($"Message from server: {_msg}");
        Client.instance.myId = _myId;
        ClientSend.WelcomeReceived();
    }
Exemplo n.º 2
0
    public static void WelcomeReceived()
    {
        using (GameServer.Packet _packet = new GameServer.Packet((int)GameServer.ClientPackets.welcomeReceived))
        {
            _packet.Write(Client.instance.myId);
            _packet.Write(UIManager.instance.usernameField.text);

            SendTCPData(_packet);
        }
    }
Exemplo n.º 3
0
        private void ConnectCallback(IAsyncResult _result)
        {
            socket.EndConnect(_result);
            if (!socket.Connected)
            {
                return;
            }
            stream = socket.GetStream();

            receivedData = new GameServer.Packet();

            stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null);
        }
Exemplo n.º 4
0
 public void SendData(GameServer.Packet _packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
         }
     }
     catch (Exception _ex)
     {
         Debug.Log($"Error sending data to server via TCP: {_ex}");
     }
 }
Exemplo n.º 5
0
        private bool HandleData(byte[] _data)
        {
            int _packetLength = 0;

            receivedData.SetBytes(_data);
            if (receivedData.UnreadLength() >= 4)
            {
                _packetLength = receivedData.ReadInt();
                if (_packetLength <= 0)
                {
                    return(true);
                }
            }

            while (_packetLength > 0 && _packetLength <= receivedData.UnreadLength())
            {
                byte[] _packetBytes = receivedData.ReadBytes(_packetLength);
                ThreadManager.ExecuteOnMainThread(() =>
                {
                    using (GameServer.Packet _packet = new GameServer.Packet(_packetBytes))
                    {
                        int _packetId = _packet.ReadInt();
                        packetHandlers[_packetId](_packet);
                    }
                });

                _packetLength = 0;
                if (receivedData.UnreadLength() >= 4)
                {
                    _packetLength = receivedData.ReadInt();
                    if (_packetLength <= 0)
                    {
                        return(true);
                    }
                }
            }

            if (_packetLength <= 1)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
 public void SendData(Packet _packet)
 {
     Server.SendUDPData(endPoint, _packet);
 }
Exemplo n.º 7
0
 private static void SendTCPData(GameServer.Packet _packet)
 {
     _packet.WriteLength();
     Client.instance.tcp.SendData(_packet);
 }