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(); }
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); } }
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); }
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}"); } }
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); }
public void SendData(Packet _packet) { Server.SendUDPData(endPoint, _packet); }
private static void SendTCPData(GameServer.Packet _packet) { _packet.WriteLength(); Client.instance.tcp.SendData(_packet); }