Exemple #1
0
        public static TCPProcessCmdResults ProcessMarryInit(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            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);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "", nID);
                return(TCPProcessCmdResults.RESULT_FAILED);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (fields.Length != 2)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), fields.Length), null, true);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "", nID);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                int        roleID   = Convert.ToInt32(fields[0]);
                int        spouseID = 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);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "", nID);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                if (client.ClientSocket.IsKuaFuLogin)
                {
                    client.sendCmd(nID, string.Format("{0}:{1}:{2}", -12, roleID, spouseID), false);
                    tcpOutPacket = null;
                    return(TCPProcessCmdResults.RESULT_OK);
                }
                MarryResult result = MarryLogic.MarryInit(client, spouseID);
                string      strcmd = string.Format("{0}:{1}:{2}", (int)result, roleID, spouseID);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false, false);
            }
            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "", nID);
            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Exemple #2
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);
        }