Esempio n. 1
0
 public void Serialize(int id, string msg)
 {
     _packet = new NetworkPacketManager();
     _packet.AddTagPacket(TagPacket.ServerAccepted);
     _packet.AddInt32(id);
     _packet.AddString(msg);
 }
Esempio n. 2
0
 public void Serialize(string serverName, int maxPlayers, string clientVer)
 {
     _packet = new NetworkPacketManager();
     _packet.AddTagPacket(TagPacket.ServerInfo);
     _packet.AddString(serverName);
     _packet.AddInt32(maxPlayers);
     _packet.AddString(clientVer);
 }
Esempio n. 3
0
    public void Deserialize(byte[] data)
    {
        var tmpPacket = new NetworkPacketManager(data);

        tmpPacket.GetTagPacket();
        this.ID      = tmpPacket.GetInt32();
        this.Message = tmpPacket.GetString();
    }
    private void OnClientConnected(int connectionId)
    {
        Logger.Log($"New client connected: {connectionId}");
        var msg = new NetworkPacketManager();

        msg.AddTagPacket(TagPacket.ServerAccepted);
        msg.AddUInt32((uint)connectionId);
        msg.AddString("TEST 0 1 2 3 4 5");
        _server.Send(connectionId, msg.Buffer);
        Logger.Log($"Send back msg to new client", Logger.LOG_TYPE.INFO, "S->C");
    }
Esempio n. 5
0
    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;
        }
    }