Пример #1
0
        //5aLkUIavxDlOBlNnbru3ZnR8sdVdaDUk

        public static byte[] des_decode(byte[] key, byte[] token)
        {
            UInt32[] ESK = new UInt32[32];
            des_key(ESK, key);
            UInt32[] SK = new UInt32[32];
            int      i;

            for (i = 0; i < 32; i += 2)
            {
                SK[i]     = ESK[30 - i];
                SK[i + 1] = ESK[31 - i];
            }

            int tokenSize = token.Length;

            if (((tokenSize & 7) != 0) || tokenSize == 0)
            {
                DebugLogger.DebugError(String.Format("Invalid des crypt text length %d", (int)tokenSize));
            }

            byte[] buffer;
            if (tokenSize > 256)
            {
                buffer = new byte[tokenSize];
            }
            else
            {
                buffer = new byte[tokenSize];
            }

            for (i = 0; i < tokenSize; i += 8)
            {
                des_crypt(SK, token, i, buffer, i);
            }
            int padding = 1;

            for (i = tokenSize - 1; i >= tokenSize - 8; i--)
            {
                if (buffer[i] == 0)
                {
                    padding++;
                }
                else if (buffer[i] == 0x80)
                {
                    break;
                }
                else
                {
                    DebugLogger.DebugError("Invalid des crypt text");
                }
            }
            if (padding > 8)
            {
                DebugLogger.DebugError("Invalid des crypt text");
            }

            //lua_pushlstring(L, (const char *)buffer, textsz - padding);

            return(buffer);
        }
Пример #2
0
        private void RpcNotify(byte[] data)
        {
            var msg = ProtobufDecoder(data);

            DebugLogger.Debug(msg.OpCode.ToString());//NotifyInfo

            if (msg.OpCode == OPCODE.NotifyInfo)
            {
                var seq = msg.NotifyInfo.Sequence;
                if (seq > 0)
                {
                    DebugLogger.Debug(seq.ToString());//1
                    //GameNodeRpc.NotificationMsg.text = seq.ToString() + "\n";
                    // clientReceiveSeq = seq;
                }

                var rpcFunc = msg.NotifyInfo.RpcFunc;
                Debug.Log(rpcFunc.ToString());//isMatchSuccess
                if (severMonitorCallback.ContainsKey(rpcFunc.ToString()))
                {
                    severMonitorCallback[rpcFunc.ToString()](msg);//执行注册的函数isMatchSuccess
                }
                if (rpcFunc == null)
                {
                    DebugLogger.DebugError("RpcNotify wrong fucntion code");
                }
                else
                {
                    //object retParam = MessagePackDecoder<object>(msg.NotifyInfo.RpcParams);
                    //int i = 0;
                    //GameNodeRpc.NotificationMsg.text += retParam.ToString();
                    //Debug.Log(retParam.ToString());
                }
            }
        }
Пример #3
0
        private void RpcNotify(byte[] data)
        {
            var msg = ProtobufDecoder(data);

            DebugLogger.Debug(msg.OpCode.ToString());

            if (msg.OpCode == OPCODE.NotifyInfo)
            {
                var seq = msg.NotifyInfo.Sequence;
                if (seq > 0)
                {
                    DebugLogger.Debug(seq.ToString());
                    GameNodeRpc.NotificationMsg.text = seq.ToString() + "\n";
                    // clientReceiveSeq = seq;
                }

                var rpcFunc = msg.NotifyInfo.RpcFunc;
                if (rpcFunc == null)
                {
                    DebugLogger.DebugError("RpcNotify wrong fucntion code");
                }
                else
                {
                    object retParam = MessagePackDecoder <object>(msg.NotifyInfo.RpcParams);
                    int    i        = 0;
                    GameNodeRpc.NotificationMsg.text += retParam.ToString();
                }
            }
        }
Пример #4
0
        static void des_key(UInt32[] SK, byte[] key)
        {
            int keySize = key.Length;

            if (keySize != 8)
            {
                DebugLogger.DebugError("Invalid key size  need 8 bytes");
            }
            des_main_ks(SK, key);
        }
Пример #5
0
        static void read64(byte[] x, byte[] y, UInt32[] xx, UInt32[] yy)
        {
            int size = x.Length;

            if (size != 8)
            {
                DebugLogger.DebugError("Invalid uint64 x");
            }
            size = y.Length;
            if (size != 8)
            {
                DebugLogger.DebugError("Invalid uint64 y");
            }
            xx[0] = (UInt32)x[0] | (UInt32)x[1] << 8 | (UInt32)x[2] << 16 | (UInt32)x[3] << 24;
            xx[1] = (UInt32)x[4] | (UInt32)x[5] << 8 | (UInt32)x[6] << 16 | (UInt32)x[7] << 24;
            yy[0] = (UInt32)y[0] | (UInt32)y[1] << 8 | (UInt32)y[2] << 16 | (UInt32)y[3] << 24;
            yy[1] = (UInt32)y[4] | (UInt32)y[5] << 8 | (UInt32)y[6] << 16 | (UInt32)y[7] << 24;
        }
Пример #6
0
        //---------------------dh---------------------------------------

        public static byte[] dh_exchange(byte[] data)
        {
            int size = data.Length;

            if (size != 8)
            {
                DebugLogger.DebugError("Invalid dh uint64 key");
            }
            UInt32[] xx = new UInt32[2];
            xx[0] = (UInt32)data[0] | (UInt32)data[1] << 8 | (UInt32)data[2] << 16 | (UInt32)data[3] << 24;
            xx[1] = (UInt32)data[4] | (UInt32)data[5] << 8 | (UInt32)data[6] << 16 | (UInt32)data[7] << 24;

            UInt64 r = powmodp(5, (UInt64)xx[0] | (UInt64)xx[1] << 32);

            byte[] result = new byte[8];
            push64(r, result);
            return(result);
        }
Пример #7
0
 // 接受服务端发送的消息 调用相关的回调函数
 public void MyUpdate()
 {
     while (reciveQueue.Count > 0)
     {
         var  msg = reciveQueue.Dequeue();
         uint session;
         var  recData = DataPack.UnPack(msg, out session);
         if (recData.Length <= 0)
         {
             // 心跳包,重置心跳计数
             heartCount = 0;
             continue;
         }
         if (session == 0)
         {
             RpcNotify(recData);
         }
         else if (sessionToCallback.ContainsKey(session))
         {
             var callback = sessionToCallback[session].CallBackFunc;
             if (null != callback)
             {
                 callback(recData);
             }
             // 加锁删除数据
             lock (sessionToCallback)
             {
                 sessionToCallback.Remove(session);
                 netProtocol.WaitRecive--;
             }
         }
         else
         {
             DebugLogger.DebugError("Session invalid:" + session);
         }
     }
 }
Пример #8
0
        public static NodeInfo ProcessLoginData(byte[] data)
        {
            if (data.Length < 2)
            {
                DebugLogger.Debug("Data Length is Less Than 2 ! Got " + data.Length, NetUtil.ErrorColor);
                throw new NetworkingException((int)ErrorCode.DataError);
            }

            UInt32 code = ((UInt32)data[0] << 8) + (UInt32)data[1];

            if (code != (int)ErrorCode.Success)
            {
                if (code == (int)ErrorCode.Forbidden || code == (int)ErrorCode.LoginBusy)
                {
                    byte[] b_message = new byte[data.Length - 2];
                    Buffer.BlockCopy(data, 2, b_message, 0, data.Length - 2);
                    var    base64Str = Encoding.Default.GetString(b_message);
                    string message   = Encoding.Default.GetString(Convert.FromBase64String(base64Str));//Convert.ToBase64String(b_message);
                    DebugLogger.DebugError("Forbidden LoginBusy");
                    throw new NetworkingException((int)code, message);
                }
                else
                {
                    DebugLogger.Debug("Login Code is Not Equal 200 ! Got " + code, NetUtil.ErrorColor);
                    throw new NetworkingException((int)code);
                }
            }

            byte[] auth_return_bytes = new byte[data.Length - 2];
            Buffer.BlockCopy(data, 2, auth_return_bytes, 0, data.Length - 2);
            string auth_return = Encoding.Default.GetString(auth_return_bytes);

            string[] strs = Regex.Split(auth_return, "@([^#]*)#");
            if (strs.Length != 3)
            {
                DebugLogger.Debug("Network Strs Length Error, Required 3 Got " + strs.Length, NetUtil.ErrorColor);
                throw new NetworkingException((int)ErrorCode.DataError);
            }

            string uid    = Encoding.Default.GetString(Convert.FromBase64String(strs[0]));
            string server = Encoding.Default.GetString(Convert.FromBase64String(strs[1]));

            string[] infos = Regex.Split(strs[2], "#");
            if (infos.Length != 2)
            {
                DebugLogger.Debug("Network Infos Length Error, Required 2 Got " + infos.Length, NetUtil.ErrorColor);
                throw new NetworkingException((int)ErrorCode.DataError);
            }

            string netinfo    = Encoding.Default.GetString(Convert.FromBase64String(infos[0]));
            string loginToken = Encoding.Default.GetString(Convert.FromBase64String(infos[1]));

            string[] netStrs = Regex.Split(netinfo, ":");
            if (netStrs.Length != 2)
            {
                DebugLogger.Debug("Network NetStrs Length Error, Required 2 Got " + netStrs.Length, NetUtil.ErrorColor);
                throw new NetworkingException((int)ErrorCode.DataError);
            }
            string[] ids = Regex.Split(uid, ":");
            if (ids.Length != 2)
            {
                DebugLogger.Debug("Network Ids Length Error, Required 2 Got " + ids.Length, NetUtil.ErrorColor);
                throw new NetworkingException((int)ErrorCode.DataError);
            }
            DebugLogger.Debug("ProcessLoginData2");
            //#if UNITY_EDITOR
            DebugLogger.Debug("login success,UID:" + ids[0] + "  subid: " + ids[1] +
                              "  gameServer: " + server + "  nodeHost:" + netStrs[0] +
                              "  nodePort:" + netStrs[1] + "  token:" + loginToken);
//#endif
            return(new NodeInfo(ids[0], ids[1], server, netStrs[0], Convert.ToInt32(netStrs[1]), loginToken));
        }