Inheritance: MonoBehaviour
Beispiel #1
0
    void ack_moveleave(int err, wire obj)
    {
        a_moveleave ack = (a_moveleave)obj;

        EntityManager.RemoveCharacter(ack.uid);
    }
Beispiel #2
0
 void ack_gatekick(int err, wire obj)
 {
     Debug.Log("GateKick");
     StateManager.Instance.SwitchState("LoginState");
 }
Beispiel #3
0
    public void Update()
    {
        if (socket_status == NetSocket.CLOSE)
        {
            return;
        }
        switch (socket_status)
        {
        case NetSocket.CONNECTING:
        case NetSocket.DISCONNECT:
            if (socket.Status == NetSocket.CONNECTED)
            {
                socket_status = NetSocket.CONNECTED;
                if (event_connect != null)
                {
                    event_connect();
                    event_connect = null;
                }
            }
            break;
        }
        if (socket.Length < 2)
        {
            if (socket.Status == NetSocket.DISCONNECT)
            {
                if (event_close != null)
                {
                    event_close();
                }
                socket_status = NetSocket.DISCONNECT;
                Debug.Log("[NetProtocol] Reconnect addr " + connect_addr + ":" + connect_port);
                socket.Connect(connect_addr, connect_port);
            }
            return;
        }
        if (length_val == 0)
        {
            socket.Read(buffer, 2);
            length_val = BitConverter.ToInt16(buffer, 0);
            length_val = System.Net.IPAddress.NetworkToHostOrder(length_val);
        }
        if (socket.Length < length_val)
        {
            return;
        }
        if (buffer.Length < length_val)
        {
            buffer = new byte[length_val];
        }
        socket.Read(buffer, 4);
        int cmd = BitConverter.ToInt32(buffer, 0);

        Debug.Assert(length_val > 4);
        length_val -= sizeof(int);
        socket.Read(buffer, length_val);
        if (!protocol_obj.ContainsKey(cmd))
        {
            Debug.Log("[NetProtocol] can't has handler of cmd[" + cmd + "]");
            return;
        }
        wire obj = protocol_obj[cmd];
        int  err = obj._parse(buffer, length_val);

        length_val = 0;
        //Debug.Log("[NetProtocol] Process cmd[" + obj._name() + "]Err:" + err);
        if (err < 0)
        {
            return;
        }
        StateManager.Instance.DispatchState(cmd, obj);
        return;
    }