Пример #1
0
        public static TCPProcessCmdResults ProcessMarryReply(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                string[] fields = cmdData.Split(':');
                if (fields.Length != 3)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int roleID   = Convert.ToInt32(fields[0]);
                int sourceID = Convert.ToInt32(fields[1]);
                int accept   = Convert.ToInt32(fields[2]);

                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                MarryResult result = MarryReply(client, sourceID, accept);

                string strcmd = string.Format("{0}:{1}:{2}", (int)result, roleID, sourceID);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Пример #2
0
        public TCPProcessCmdResults ProcessMarryPartyCreate(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false)), null, true);
                return(TCPProcessCmdResults.RESULT_FAILED);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (fields.Length != 3)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), fields.Length), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                int        roleID    = Convert.ToInt32(fields[0]);
                int        partyType = Convert.ToInt32(fields[1]);
                long       startTime = Convert.ToInt64(fields[2]);
                GameClient client    = GameManager.ClientMgr.FindClient(socket);
                if (KuaFuManager.getInstance().ClientCmdCheckFaild(nID, client, ref roleID))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), roleID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                if (client.ClientSocket.IsKuaFuLogin)
                {
                    client.sendCmd(nID, string.Format("{0}:{1}", -12, roleID), false);
                    return(TCPProcessCmdResults.RESULT_OK);
                }
                MarryPartyResult result = this.MarryPartyCreate(client, partyType, startTime);
                string           strcmd = string.Format("{0}:{1}", (int)result, roleID);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessMarryPartyCreate", false, false);
            }
            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Пример #3
0
 public static bool CheckTCPCmdHandle <T>(TMSKSocket socket, int nID, byte[] data, int count, out T cmdData) where T : class, IProtoBuffData, new()
 {
     cmdData = default(T);
     try
     {
         cmdData = DataHelper.BytesToObject2 <T>(data, 0, count, socket.m_Socket);
     }
     catch (Exception)
     {
         LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false)), null, true);
         return(false);
     }
     return(null != cmdData);
 }
Пример #4
0
        /// <summary>
        /// 透传到DBServer处理
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="nID"></param>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public TCPProcessCmdResults transmission(TMSKSocket socket, int nID, byte[] data, int count)
        {
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

//             GameClient client = GameManager.ClientMgr.FindClient(socket);
//             if (null == client)
//             {
//                 LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
//                 return TCPProcessCmdResults.RESULT_FAILED;
//             }

            try
            {
                byte[] bytesData = Global.SendAndRecvData(TCPClientPool.getInstance(), TCPOutPacketPool.getInstance(), data, count, nID);
                if (null == bytesData)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("与DBServer通讯失败, CMD={0}", (TCPGameServerCmds)nID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                Int32 length = BitConverter.ToInt32(bytesData, 0);
                Int16 cmd    = BitConverter.ToInt16(bytesData, 4);

                TCPOutPacket tcpOutPacket = TCPOutPacketPool.getInstance().Pop();
                tcpOutPacket.PacketCmdID = (Int16)cmd;
                tcpOutPacket.FinalWriteData(bytesData, 6, length - 2);

                //client.sendCmd(tcpOutPacket);
                TCPManager.getInstance().MySocketListener.SendData(socket, tcpOutPacket);
                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                // 格式化异常错误信息
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false);
            }


            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Пример #5
0
 /// <summary>
 /// 为不同的连接重复使用
 /// </summary>
 public void Reset()
 {
     lock (this)
     {
         _Socket            = null;
         _PacketCmdID       = 0;
         _PacketDataSize    = 0;
         PacketDataHaveSize = 0;
         IsWaitingData      = false;
         CmdHeaderSize      = 0;
         _cmdPacketPool.Clear();//以前少写了
         _LastCheckTicks = 0;
     }
 }
Пример #6
0
        /// <summary>
        /// 获得活动信息,根据活动type,角色id
        /// </summary>
        /// <param name="tcpMgr"></param>
        /// <param name="socket"></param>
        /// <param name="tcpClientPool"></param>
        /// <param name="tcpRandKey"></param>
        /// <param name="pool"></param>
        /// <param name="nID"></param>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <param name="tcpOutPacket"></param>
        /// <returns></returns>
        public static TCPProcessCmdResults ProcessGetActiveInfo(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID));

                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN);
                return(TCPProcessCmdResults.RESULT_DATA);
            }

            try
            {
                string[] fields = cmdData.Split(':');
                if (fields.Length != 2)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}",
                                                                      (TCPGameServerCmds)nID, fields.Length, cmdData));

                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", (int)TCPGameServerCmds.CMD_DB_ERR_RETURN);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                //角色id
                int roleID = Convert.ToInt32(fields[0]);
                //活动类型
                int        activetype = Convert.ToInt32(fields[1]);
                GameClient client     = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                //定位角色成功之后将命令转发给gamedbserver
                TCPProcessCmdResults ret = Global.RequestToDBServer2(tcpClientPool, pool, nID, Global.GetActivityRequestCmdString((ActivityTypes)activetype, client), out tcpOutPacket, client.ServerId);
                return(ret);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "", false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Пример #7
0
        public TCPProcessCmdResults ProcessOpenVideoCmd(TMSKSocket socket, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID), null, true);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 1700);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (fields.Length != 1)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}", (TCPGameServerCmds)nID, fields.Length, cmdData), null, true);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 1700);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                int        roleID = Convert.ToInt32(fields[0]);
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (KuaFuManager.getInstance().ClientCmdCheckFaild(nID, client, ref roleID))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), roleID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                VideoData roomData = this.GetVideoRoomData(client);
                if (roomData == null)
                {
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "", nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                int    filterStatus = this.GetPlayerFilterStatus(client, roomData);
                string strcmd       = string.Format("{0}:{1}:{2}", roomData.TalkID, roomData.PassWord, filterStatus);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false, false);
            }
            return(TCPProcessCmdResults.RESULT_DATA);
        }
Пример #8
0
        /// <summary>
        /// 直接发送策略数据
        /// </summary>
        /// <param name="tcpInStream"></param>
        private void DirectSendPolicyFileData(TCPInPacket tcpInPacket)
        {
            TMSKSocket s = tcpInPacket.CurrentSocket;

            try
            {
                s.Send(TCPPolicy.PolicyServerFileContent, TCPPolicy.PolicyServerFileContent.Length, SocketFlags.None);

                LogManager.WriteLog(LogTypes.Info, string.Format("向客户端返回策略文件数据: {0}", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket)));
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Info, string.Format("向客户端返回策略文件时,socket出现异常,对方已经关闭: {0}", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket)));
            }
        }
Пример #9
0
        public bool OnUserLogin2(TMSKSocket socket, int verSign, string userID, string userName, string lastTime, string isadult, string signCode)
        {
            WebLoginToken webLoginToken = new WebLoginToken
            {
                VerSign  = verSign,
                UserID   = userID,
                UserName = userName,
                LastTime = lastTime,
                Isadult  = isadult,
                SignCode = signCode
            };

            socket.ClientKuaFuServerLoginData.WebLoginToken = webLoginToken;
            return(true);
        }
Пример #10
0
        public void HandleSystemChargeMoney(string userID, int addMoney)
        {
            TMSKSocket clientSocket = GameManager.OnlineUserSession.FindSocketByUserID(userID);

            if (null != clientSocket)
            {
                LogManager.WriteLog(LogTypes.SQL, string.Format("通知账户ID{0}的角色更新元宝数量", userID), null, true);
                GameClient otherClient = GameManager.ClientMgr.FindClient(clientSocket);
                if (null != otherClient)
                {
                    GameManager.ClientMgr.AddUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, otherClient, 0, "", ActivityTypes.None, "");
                    GameManager.logDBCmdMgr.AddDBLogInfo(-1, "钻石", "GM命令强迫更新", "系统", otherClient.ClientData.RoleName, "增加", addMoney, otherClient.ClientData.ZoneID, otherClient.strUserID, otherClient.ClientData.UserMoney, otherClient.ServerId, null);
                }
            }
        }
Пример #11
0
 public void RemoveSession(TMSKSocket clientSocket)
 {
     if (null != clientSocket)
     {
         string userID = "";
         lock (this)
         {
             if (this._S2UDict.TryGetValue(clientSocket, out userID))
             {
                 this._S2UDict.Remove(clientSocket);
                 this._U2SDict.Remove(userID);
             }
         }
     }
 }
Пример #12
0
 public TCPCmdWrapper(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count)
 {
     this.tcpMgr        = tcpMgr;
     this.socket        = socket;
     this.tcpClientPool = tcpClientPool;
     this.tcpRandKey    = tcpRandKey;
     this.pool          = pool;
     this.nID           = nID;
     this.data          = data;
     this.count         = count;
     lock (TCPCmdWrapper.CountLock)
     {
         TCPCmdWrapper.TotalWrapperCount++;
     }
 }
Пример #13
0
 public void RemoveUserName(TMSKSocket clientSocket)
 {
     if (null != clientSocket)
     {
         lock (this)
         {
             string userName = null;
             if (this._S2UNameDict.TryGetValue(clientSocket, out userName))
             {
                 this._S2UNameDict.Remove(clientSocket);
                 this._UName2SDict.Remove(userName);
             }
         }
     }
 }
Пример #14
0
        public static TCPProcessCmdResults ProcessGetLingYuList(
            TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool,
            TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            string[] fields = null;
            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                fields = cmdData.Split(':');
                if (1 != fields.Length)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int        roleID = Convert.ToInt32(fields[0]);
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                List <LingYuData> dataList  = LingYuManager.GetLingYuList(client);
                byte[]            bytesData = DataHelper.ObjectToBytes <List <LingYuData> >(dataList);
                GameManager.ClientMgr.SendToClient(client, bytesData, nID);

                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessGetLingYuList", false);
            }

            return(TCPProcessCmdResults.RESULT_DATA);
        }
Пример #15
0
 /// <summary>
 /// 删除一个在线的回话
 /// </summary>
 /// <param name="clientSocket"></param>
 public void RemoveSession(TMSKSocket clientSocket)
 {
     if (null == clientSocket)
     {
         return;
     }
     lock (this)
     {
         string userID = "";
         if (_S2UDict.TryGetValue(clientSocket, out userID))
         {
             _S2UDict.Remove(clientSocket);
             _U2SDict.Remove(userID);
         }
     }
 }
Пример #16
0
 /// <summary>
 /// 删除一个在线的用户名称
 /// </summary>
 /// <param name="clientSocket"></param>
 public void RemoveUserName(TMSKSocket clientSocket)
 {
     if (null == clientSocket)
     {
         return;
     }
     lock (this)
     {
         string userName = null;
         if (_S2UNameDict.TryGetValue(clientSocket, out userName))
         {
             _S2UNameDict.Remove(clientSocket);
             _UName2SDict.Remove(userName);
         }
     }
 }
Пример #17
0
        public TCPProcessCmdResults ProcessGetFirstChargeInfoCMD(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false)), null, true);
                return(TCPProcessCmdResults.RESULT_FAILED);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                int        roleID = Convert.ToInt32(fields[0]);
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (KuaFuManager.getInstance().ClientCmdCheckFaild(nID, client, ref roleID))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), roleID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                string[] dbFields = null;
                Global.RequestToDBServer(Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, 671, client.strUserID, out dbFields, client.ServerId);
                if (null == dbFields)
                {
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                string returndata = dbFields[0];
                if (returndata == "-1")
                {
                    returndata = "";
                }
                string strcmd = string.Format("{0}", returndata);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessGetFirstChargeInfoCMD", false, false);
            }
            return(TCPProcessCmdResults.RESULT_DATA);
        }
Пример #18
0
        public static TCPProcessCmdResults ProcessGetYueKaData(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false)), null, true);
                return(TCPProcessCmdResults.RESULT_FAILED);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (1 != fields.Length)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), fields.Length), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                int        roleID = Convert.ToInt32(fields[0]);
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (KuaFuManager.getInstance().ClientCmdCheckFaild(nID, client, ref roleID))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), roleID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                YueKaData ykData = null;
                lock (client.ClientData.YKDetail)
                {
                    ykData = client.ClientData.YKDetail.ToYueKaData();
                }
                GameManager.ClientMgr.SendToClient(client, DataHelper.ObjectToBytes <YueKaData>(ykData), nID);
                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessGetYueKaData", false, false);
            }
            return(TCPProcessCmdResults.RESULT_DATA);
        }
Пример #19
0
        public static TCPProcessCmdResults ProcessGetYueKaAward(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, global::Server.Protocol.TCPOutPacketPool pool, int nID, byte[] data, int count, out global::Server.Protocol.TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            string[] fields = null;
            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                fields = cmdData.Split(':');
                if (2 != fields.Length)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int        roleID = Convert.ToInt32(fields[0]);
                int        day    = Convert.ToInt32(fields[1]);
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                YueKaError err = _GetYueKaAward(client, day);
                string     cmd = string.Format("{0}:{1}:{2}", roleID, (int)err, day);
                GameManager.ClientMgr.SendToClient(client, cmd, nID);
                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessGetYueKaData", false);
            }

            return(TCPProcessCmdResults.RESULT_DATA);
        }
Пример #20
0
        public static TCPProcessCmdResults ProcessReqZhuHun(
            TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool,
            TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            string[] fields = null;
            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                fields = cmdData.Split(':');
                if (1 != fields.Length)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int        roleID = Convert.ToInt32(fields[0]);
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                ZhuLingZhuHunError e      = ZhuLingZhuHunManager.ReqZhuHun(client);
                string             strcmd = string.Format("{0}:{1}:{2}", roleID, (int)e, client.ClientData.MyWingData.ZhuHunNum);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessReqZhuHun", false);
            }

            return(TCPProcessCmdResults.RESULT_DATA);
        }
Пример #21
0
        public ushort LastPacketCmdID(TMSKSocket s)
        {
            ushort cmd = 0;

            if (s != null && this.dictInPackets != null)
            {
                lock (this.dictInPackets)
                {
                    TCPInPacket inPacket = null;
                    if (this.dictInPackets.TryGetValue(s, out inPacket))
                    {
                        cmd = inPacket.LastPacketCmdID;
                    }
                }
            }
            return(cmd);
        }
Пример #22
0
        public UInt16 LastPacketCmdID(TMSKSocket s)
        {
            UInt16 cmd = (UInt16)TCPGameServerCmds.CMD_UNKNOWN;

            if (s != null && dictInPackets != null)
            {
                lock (dictInPackets)
                {
                    TCPInPacket inPacket = null;
                    if (dictInPackets.TryGetValue(s, out inPacket))
                    {
                        cmd = inPacket.LastPacketCmdID;
                    }
                }
            }
            return(cmd);
        }
Пример #23
0
        public static TCPProcessCmdResults ProcessUsrCheckState(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false)), null, true);
                return(TCPProcessCmdResults.RESULT_FAILED);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (2 != fields.Length)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), fields.Length), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                string      userid   = fields[0];
                SecPwdState pwdState = SecondPasswordManager.GetSecPwdState(userid);
                string      cmdRsp;
                if (pwdState != null)
                {
                    cmdRsp = string.Format("{0}:{1}", 1, pwdState.NeedVerify ? 1 : 0);
                }
                else
                {
                    cmdRsp = string.Format("{0}:{1}", 0, 0);
                }
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, cmdRsp, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false, false);
            }
            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Пример #24
0
 public TCPProcessCmdResults OnResponse(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
 {
     tcpOutPacket = null;
     try
     {
         string[] fields = new UTF8Encoding().GetString(data, 0, count).Split(new char[]
         {
             ':'
         });
         if (fields == null || fields.Length <= 2)
         {
             return(TCPProcessCmdResults.RESULT_FAILED);
         }
         int        roleId = Convert.ToInt32(fields[0]);
         int        index  = Convert.ToInt32(fields[1]);
         GameClient client = GameManager.ClientMgr.FindClient(socket);
         if (KuaFuManager.getInstance().ClientCmdCheckFaild(nID, client, ref roleId))
         {
             LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), roleId), null, true);
             return(TCPProcessCmdResults.RESULT_FAILED);
         }
         if (index < 0 || index >= 2)
         {
             LogManager.WriteLog(LogTypes.Error, string.Format("角色返回敏感数据索引错误,roleid={0}, rolename={1}, index={2}", roleId, client.ClientData.RoleName, index), null, true);
             return(TCPProcessCmdResults.RESULT_FAILED);
         }
         lock (client.InterestingData)
         {
             InterestingData.Item item = client.InterestingData.itemArray[index];
             if (item != null)
             {
                 item.LastResponseMs = TimeUtil.NOW();
                 item.ResponseCount++;
                 if (index == 0)
                 {
                     this._CheckSpeed(client, item, fields);
                 }
             }
         }
     }
     catch
     {
     }
     return(TCPProcessCmdResults.RESULT_OK);
 }
Пример #25
0
 public static void BroadCastDetectHook(List <string> uidList)
 {
     if (uidList != null)
     {
         foreach (string uid in uidList)
         {
             TMSKSocket clientSocket = GameManager.OnlineUserSession.FindSocketByUserID(uid);
             if (null != clientSocket)
             {
                 GameClient client = GameManager.ClientMgr.FindClient(clientSocket);
                 if (client != null)
                 {
                     FileBanLogic.SendMagicCrashMsg(client, MagicCrashUnityType.DetectHook);
                 }
             }
         }
     }
 }
Пример #26
0
 public static void Tick()
 {
     FileBanLogic.LoadBanFile();
     if (null != FileBanLogic.m_BanList)
     {
         if (FileBanLogic.m_IsNeedClear > 0)
         {
             FileBanLogic.m_BanList.Clear();
             FileBanLogic.m_IsNeedClear = 0;
         }
         bool bCrashForce = GameManager.VersionSystemOpenMgr.IsVersionSystemOpen("CrashUnityForce");
         int  i           = 20;
         while (i > 0 && FileBanLogic.m_BanList.Count > 0)
         {
             i--;
             string userID = FileBanLogic.m_BanList[FileBanLogic.m_BanList.Count - 1];
             FileBanLogic.m_BanList.RemoveAt(FileBanLogic.m_BanList.Count - 1);
             BanManager.BanUserID2Memory(userID);
             TMSKSocket clientSocket = GameManager.OnlineUserSession.FindSocketByUserID(userID);
             if (null != clientSocket)
             {
                 GameClient gameClient = GameManager.ClientMgr.FindClient(clientSocket);
                 if (null != gameClient)
                 {
                     RoleData roleData = new RoleData
                     {
                         RoleID = -70
                     };
                     gameClient.sendCmd <RoleData>(104, roleData, false);
                     if (bCrashForce)
                     {
                         FileBanLogic.SendMagicCrashMsg(gameClient, MagicCrashUnityType.CrashTimeOut);
                     }
                     LogManager.WriteLog(LogTypes.FileBan, string.Format("FileBanLogic ban2 userID={0} roleID={1}", userID, gameClient.ClientData.RoleID), null, true);
                 }
                 else
                 {
                     Global.ForceCloseSocket(clientSocket, "被禁止登陆", true);
                     LogManager.WriteLog(LogTypes.FileBan, string.Format("FileBanLogic ForceCloseSocket userID={0}", userID), null, true);
                 }
             }
         }
     }
 }
        public void OnMoneyChargeEvent(string userid, int roleid, int addMoney, int superInputFanLi)
        {
            DateTime            now            = TimeUtil.NowDateTime();
            JieriSuperInputData superInputData = null;

            if (this.JieriSuperInputDict.TryGetValue(superInputFanLi, out superInputData))
            {
                GameClient otherClient  = null;
                TMSKSocket clientSocket = GameManager.OnlineUserSession.FindSocketByUserID(userid);
                if (null != clientSocket)
                {
                    otherClient = GameManager.ClientMgr.FindClient(clientSocket);
                }
                lock (JieriSuperInputActivity._SuperInputMutex)
                {
                    List <int> countList = this.GetFullPurchaseList(now);
                    if (countList[0] == TimeUtil.GetOffsetDay(now) && countList[1] == superInputFanLi)
                    {
                        List <int> list;
                        (list = countList)[4] = list[4] + 1;
                        this.SaveFullPurchaseList(countList);
                    }
                }
                if (null == otherClient)
                {
                    if (superInputData.MutiNum > 0)
                    {
                        GameManager.ClientMgr.AddOfflineUserMoney(Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, roleid, roleid.ToString(), (superInputData.MutiNum - 1) * Global.TransMoneyToYuanBao(addMoney), "节日超级充值返利钻石(离线)", 0, userid);
                    }
                }
                else
                {
                    if (superInputData.MutiNum > 0)
                    {
                        GameManager.ClientMgr.AddUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, otherClient, (superInputData.MutiNum - 1) * Global.TransMoneyToYuanBao(addMoney), "节日超级充值返利钻石", ActivityTypes.None, "");
                    }
                    if (superInputData.PurchaseNum > 0 && now >= superInputData.BeginTime && now <= superInputData.EndTime)
                    {
                        string cmd = this.BuildSuperInputFanLiActInfoForClient(otherClient);
                        otherClient.sendCmd(1622, cmd, false);
                    }
                }
            }
        }
Пример #28
0
 public static TCPProcessCmdResults ProcClrSecPwd(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
 {
     tcpOutPacket = null;
     try
     {
         VerifySecondPassword verifyReq = DataHelper.BytesToObject <VerifySecondPassword>(data, 0, count);
         if (verifyReq == null)
         {
             LogManager.WriteLog(LogTypes.Error, string.Format("解析指令错误, cmd={0}", nID), null, true);
             return(TCPProcessCmdResults.RESULT_FAILED);
         }
         string uid = GameManager.OnlineUserSession.FindUserID(socket);
         if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(verifyReq.UserID) || uid != verifyReq.UserID)
         {
             LogManager.WriteLog(LogTypes.Error, string.Format("玩家请求清除二级密码,但是玩家发送的uid错误, {0}", Global.GetSocketRemoteEndPoint(socket, false)), null, true);
             return(TCPProcessCmdResults.RESULT_FAILED);
         }
         SecPwdState pwdState = SecondPasswordManager.GetSecPwdState(verifyReq.UserID);
         int         errcode;
         if (pwdState == null)
         {
             errcode = 2;
         }
         else if (string.IsNullOrEmpty(verifyReq.SecPwd) || verifyReq.SecPwd != pwdState.SecPwd)
         {
             errcode = 1;
         }
         else if (!SecondPasswordManager.ClearUserSecPwd(verifyReq.UserID))
         {
             errcode = 8;
         }
         else
         {
             errcode = 9;
         }
         tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, errcode.ToString(), nID);
         return(TCPProcessCmdResults.RESULT_DATA);
     }
     catch (Exception ex)
     {
         DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false, false);
     }
     return(TCPProcessCmdResults.RESULT_FAILED);
 }
Пример #29
0
 public static TCPProcessCmdResults ProcessUsrVerify(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
 {
     tcpOutPacket = null;
     try
     {
         VerifySecondPassword verifyReq = DataHelper.BytesToObject <VerifySecondPassword>(data, 0, count);
         if (verifyReq == null)
         {
             LogManager.WriteLog(LogTypes.Error, string.Format("解析指令错误, cmd={0}", nID), null, true);
             return(TCPProcessCmdResults.RESULT_FAILED);
         }
         SecPwdState pwdState = SecondPasswordManager.GetSecPwdState(verifyReq.UserID);
         int         errcode;
         int         has;
         int         need;
         if (pwdState == null)
         {
             errcode = 0;
             has     = 0;
             need    = 0;
         }
         else if (string.IsNullOrEmpty(verifyReq.SecPwd) || verifyReq.SecPwd != pwdState.SecPwd)
         {
             errcode = 1;
             has     = 1;
             need    = 1;
         }
         else
         {
             errcode             = 0;
             has                 = 1;
             need                = 0;
             pwdState.NeedVerify = false;
         }
         string rsp = string.Format("{0}:{1}:{2}", errcode, has, need);
         tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, rsp, nID);
         return(TCPProcessCmdResults.RESULT_DATA);
     }
     catch (Exception ex)
     {
         DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false, false);
     }
     return(TCPProcessCmdResults.RESULT_FAILED);
 }
Пример #30
0
        /// <summary>
        /// 接收数据通知函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private bool SocketReceived(object sender, SocketAsyncEventArgs e)
        {
            SocketListener sl          = sender as SocketListener;
            TCPInPacket    tcpInPacket = null;
            AsyncUserToken userToken   = (e.UserToken as AsyncUserToken);
            TMSKSocket     s           = userToken.CurrentSocket;

            if (GameManager.FlagOptimizeLock)
            {
                tcpInPacket = s._TcpInPacket;
                if (null == tcpInPacket)
                {
                    lock (dictInPackets) //锁定接收包队列
                    {
                        if (!dictInPackets.TryGetValue(s, out tcpInPacket))
                        {
                            tcpInPacket      = tcpInPacketPool.Pop(s, TCPCmdPacketEvent);
                            dictInPackets[s] = tcpInPacket;
                        }
                    }
                    s._TcpInPacket = tcpInPacket;
                }
            }
            else
            {
                lock (dictInPackets) //锁定接收包队列
                {
                    if (!dictInPackets.TryGetValue(s, out tcpInPacket))
                    {
                        tcpInPacket      = tcpInPacketPool.Pop(s, TCPCmdPacketEvent);
                        dictInPackets[s] = tcpInPacket;
                    }
                }
            }

            //处理收到的包
            if (!tcpInPacket.WriteData(e.Buffer, e.Offset, e.BytesTransferred))
            {
                //LogManager.WriteLog(LogTypes.Error, string.Format("接收到非法数据长度的tcp命令, 需要立即断开!"));
                return(false);
            }

            return(true);
        }