public void Deserialize(byte[] data) { var tmpPacket = new NetworkPacketManager(data); tmpPacket.GetTagPacket(); this.ID = tmpPacket.GetInt32(); this.Message = tmpPacket.GetString(); }
public void Deserialize(byte[] data) { var tmpPacket = new NetworkPacketManager(data); if (tmpPacket.GetTagPacket() != TagPacket.ServerInfo) { Logger.Log("WRONG PACKET TYPE IN 'PacketServerInfo'", Logger.LOG_TYPE.ERROR, "packet"); } else { this.ServerName = tmpPacket.GetString(); this.MaxPlayers = tmpPacket.GetInt32(); this.ClientVersion = tmpPacket.GetString(); } }
public void Run() { while (_client.Connected) { Message msg; while (_client.GetNextMessage(out msg)) { switch (msg.eventType) { case EventType.Connected: Logger.Log("CONNECTED"); break; case EventType.Data: Logger.Log("--NEW DATA RECEIVED"); var d = new NetworkPacketManager(msg.data); if (d.Buffer == null) { Logger.Log("!- EMPTY DATA BUFFED", Logger.LOG_TYPE.ERROR); } switch (d.GetTagPacket()) { case TagPacket.ServerAccepted: Logger.Log("- packed accepted received"); var dd = new PacketServerAccepted(); dd.Deserialize(d.Buffer); Logger.Log($"DATA: {dd.ID}, {dd.Message}"); var z = new PacketServerInfo(); z.Serialize("cale te", 666, "1.00"); _client.Send(z.PacketData); Logger.Log("server data packet"); break; default: Logger.Log("UNHHANDLED PACKET", Logger.LOG_TYPE.ERROR); break; } break; case EventType.Disconnected: Logger.Log("DISCONNECTED"); break; } } } }
void HandleDatapacket(Message msg) { var packet = new NetworkPacketManager(msg.data); switch (packet.GetTagPacket()) { case TagPacket.ServerAccepted: break; case TagPacket.ServerInfo: Logger.Log("- server info packet received"); var a = new PacketServerInfo(); a.Deserialize(packet.Buffer); SingleServer tmp = new SingleServer(); tmp.serverName = a.ServerName; tmp.serverMaxPlayers = a.MaxPlayers; _serverManager.AddNewServer(msg.connectionId, tmp); break; default: Logger.Log("UNHANDLED PACKED TYPE RECEIVED", Logger.LOG_TYPE.ERROR); break; } }