예제 #1
0
    public static ProtoBuf.IExtensible GetProtoData(ProtoDefine protoId, byte[] msgData)
    {
        switch (protoId)
        {
        case ProtoDefine.Handshake:
            return(NetUtilcs.Deserialize <Handshake>(msgData));

        case ProtoDefine.StartGame:
            return(NetUtilcs.Deserialize <StartGame>(msgData));

        case ProtoDefine.ChessManaul:
            return(NetUtilcs.Deserialize <ChessManaul>(msgData));

        case ProtoDefine.HitChess:
            return(NetUtilcs.Deserialize <HitChess>(msgData));

        case ProtoDefine.WinGame:
            return(NetUtilcs.Deserialize <WinGame>(msgData));

        case ProtoDefine.ChessLocation:
            return(NetUtilcs.Deserialize <ChessLocation>(msgData));

        case ProtoDefine.CloseConnect:
            return(NetUtilcs.Deserialize <CloseConnect>(msgData));

        default:
            return(null);
        }
    }
예제 #2
0
        public static NetMsgData GetMsgData(ProtoDefine protoType, IExtensible protoData, ushort length = 0)
        {
            NetMsgData data = new NetMsgData();

            data.ProtoId   = (ushort)protoType;
            data.MsgLength = length;
            data.ProtoData = protoData;
            return(data);
        }
예제 #3
0
        public static void ListenerMsg(ProtoDefine protoType, NetCallBack callBack)
        {
            if (!m_EventTable.ContainsKey(protoType))
            {
                m_EventTable.Add(protoType, null);
            }

            m_EventTable[protoType] = (NetCallBack)m_EventTable[protoType] + callBack;
        }
예제 #4
0
        //发送消息到服务器
        public void SendMsg(ProtoDefine protoType, IExtensible protoData)
        {
            //byte[] temp = Encoding.UTF8.GetBytes(msg);
            NetMsgData msg = NetMsgData.GetMsgData(protoType, protoData);

            byte[] data = NetUtilcs.PackNetMsg(msg);
            stream.Write(data, 0, data.Length);
            Debug.Log("发送消息 -> " + msg.ProtoId + data);
        }
예제 #5
0
        public static void RemoveListenerMsg(ProtoDefine protoType, NetCallBack callBack)
        {
            if (m_EventTable.ContainsKey(protoType))
            {
                m_EventTable[protoType] = (NetCallBack)m_EventTable[protoType] - callBack;

                if (m_EventTable[protoType] == null)
                {
                    m_EventTable.Remove(protoType);
                }
            }
        }
예제 #6
0
 public void SendMsg1(ProtoDefine protoType, IExtensible protoData)
 {
     if (!this.mIsRunning)
     {
         return;
     }
     lock (this.mSendLock)
     {
         mSendWaitingMsgQueue.Enqueue(NetMsgData.GetMsgData(protoType, protoData));
         Monitor.Pulse(this.mSendLock);
     }
 }
예제 #7
0
        public static void DispatcherMsg(NetMsgData msgData)
        {
            ProtoDefine protoType = (ProtoDefine)msgData.ProtoId;
            Delegate    d;

            if (m_EventTable.TryGetValue(protoType, out d))
            {
                NetCallBack callBack = d as NetCallBack;
                if (callBack != null)
                {
                    callBack(msgData.ProtoData);
                }
            }
        }
예제 #8
0
 public static void SendMsg(ProtoDefine protoType, IExtensible protoData)
 {
     SocketClient.Instance.SendMsg(protoType, protoData);
 }