Пример #1
0
        /// <summary>
        /// 精灵提取
        /// </summary>
        public static TCPProcessCmdResults ProcessMovePetCMD(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            return(TCPProcessCmdResults.RESULT_OK);

            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 != 2)
                {
                    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        dbid   = 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);
                }

                CallSpriteResult result = MovePet(client, dbid);
                string           strcmd = "";

                if (result != CallSpriteResult.Success)
                {
                    strcmd       = string.Format("{0}:{1}:{2}", (int)result, roleID, dbid);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                strcmd       = string.Format("{0}:{1}:{2}", (int)CallSpriteResult.Success, roleID, dbid);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessMovePetCMD", false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Пример #2
0
        public static TCPProcessCmdResults ProcessCallPetCMD(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 != 2)
                {
                    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        times  = 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);
                }
                string           strGetGoods = "";
                CallSpriteResult result      = CallPetManager.CallPet(client, times, out strGetGoods);
                string           strcmd;
                if (result != CallSpriteResult.Success)
                {
                    strcmd = string.Format("{0}:{1}:{2}:{3}", new object[]
                    {
                        (int)result,
                        roleID,
                        0,
                        0
                    });
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                strcmd = string.Format("{0}:{1}:{2}:{3}", new object[]
                {
                    0,
                    times,
                    strGetGoods,
                    CallPetManager.getFreeSec(client)
                });
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessCallPetCMD", false, false);
            }
            return(TCPProcessCmdResults.RESULT_FAILED);
        }