Esempio n. 1
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);
        }
Esempio n. 2
0
        public static TCPProcessCmdResults ProcessAdvanceLingYuLevel(
            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(':');
                //角色id:翎羽Type:材料不足时消耗钻石
                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]);
                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);
                }

                int type = Convert.ToInt32(fields[1]);
                int useZuanshiIfNoMaterial = Convert.ToInt32(fields[2]);

                LingYuError lyError = LingYuManager.AdvanceLingYuLevel(client, roleID, type, useZuanshiIfNoMaterial);
                LingYuData  lyData  = null;
                lock (client.ClientData.LingYuDict)
                {
                    if (!client.ClientData.LingYuDict.TryGetValue(type, out lyData))
                    {
                        lyData       = new LingYuData();
                        lyData.Type  = type;
                        lyData.Level = DEFAULT_LINGYU_LEVEL;
                        lyData.Suit  = 0;
                    }
                }

                string strcmd = string.Format("{0}:{1}:{2}:{3}", roleID, (int)lyError, lyData.Type, lyData.Level);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessAdvanceLingYuLevel", false);
            }

            return(TCPProcessCmdResults.RESULT_DATA);
        }