Exemple #1
0
    public void Register(wire obj)
    {
        int cmd = obj._tag();

        Debug.Log("[NetProtocol] Register:" + obj._name() + " tag:" + cmd);
        if (protocol_obj.ContainsKey(cmd))
        {
            Debug.Assert(protocol_obj[cmd]._tag() == obj._tag());
            return;
        }
        protocol_obj[cmd] = obj;
        return;
    }
Exemple #2
0
    public void Register(wire obj, cb_t cb)
    {
        int cmd = obj._tag();

        NetInstance.Login.Register(obj);
        NetInstance.Gate.Register(obj);
        Debug.Assert(!protocol_cb.ContainsKey(cmd));
        protocol_cb[cmd] = cb;
    }
Exemple #3
0
    public void Register(wire obj, cb_t cb)
    {
        int cmd = obj._tag();

        Debug.Log("[NetProtocol] Register:" + obj._name() + " tag:" + cmd);
        Debug.Assert(!protocol_obj.ContainsKey(cmd));
        Debug.Assert(!protocol_cb.ContainsKey(cmd));
        protocol_obj[cmd] = obj;
        protocol_cb[cmd]  = cb;
        return;
    }
    public bool Send(wire obj)
    {
        if (!isConnected())
        {
            Debug.Log("[NetProtocol] Send:" + obj._name() + " disconnect" + socket.Status);
            return(false);
        }
        int cmd = obj._tag();

        byte[] dat = null;
        obj._serialize(out dat);
        short len  = (short)(4 + dat.Length);
        int   need = len + 2;

        byte[] buffer = new byte[need];
        len = System.Net.IPAddress.HostToNetworkOrder(len);
        System.BitConverter.GetBytes(len).CopyTo(buffer, 0);
        System.BitConverter.GetBytes(cmd).CopyTo(buffer, 2);
        dat.CopyTo(buffer, 6);
        socket.Send(buffer);
        return(true);
    }