예제 #1
0
        /// <summary>
        /// 分发消息
        /// </summary>
        /// <param name="msgBuff">消息</param>
        private void Dispatch(GameServer server, byte[] msgBuff)
        {
            if (server == null || msgBuff == null)
            {
                return;
            }

            if (msgBuff.Length <= 2)
            {
                return;
            }


            ProtocolDef protocalId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 0);
            IProtocol   message    = null;

            switch (protocalId)
            {
                #region 文件管理
            case ProtocolDef.g2e_openfile_def:                    //打开文件
                message = new g2e_openfile();
                message.FromBytes(msgBuff);
                break;

            case ProtocolDef.g2e_seekfile_def:                    //移动到文件中的位置
                message = new g2e_seekfile();
                break;

            case ProtocolDef.g2e_writefile_def:                    //写入文件
                message = new g2e_writefile();
                break;

            case ProtocolDef.g2e_closefile_def:                    //关闭文件
                message = new g2e_closefile();
                break;

            case ProtocolDef.g2e_readfile_def:     //读文件
                message = new g2e_readfile();
                break;
                #endregion

                #region 游戏服务器信息
            case ProtocolDef.g2e_getcpubaseinfo_def:                    //取得CPU基本信息
                message = new g2e_getcpubaseinfo();
                break;

            case ProtocolDef.g2e_getcpuload_def:                    //取得CPU负载
                message = new g2e_getcpuload();
                break;

            case ProtocolDef.g2e_getdiskinfo_def:                    //取得磁盘信息
                message = new g2e_getdiskinfo();
                break;

            case ProtocolDef.g2e_getmeminfo_def:                    //取得内存信息
                message = new g2e_getmeminfo();
                break;

            case ProtocolDef.g2e_getprocinfo_def:                    //取得进程信息
                message = new g2e_getprocinfo();
                break;

            case ProtocolDef.g2e_getcardload_def:                    //取得网卡负载
                message = new g2e_getcardload();
                break;

            case ProtocolDef.g2e_getnetinfo_def:                    //取得网卡信息
                message = new g2e_getnetinfo();
                break;

            case ProtocolDef.g2e_getpluginfo_def:    //取得插件信息
                message = new g2e_getpluginfo();
                break;
                #endregion

                #region 其他
            case ProtocolDef.g2e_ping_def:                    //Ping
                message = new KProtocolHead();
                break;

            case ProtocolDef.g2e_exesql_def:
                message = new g2e_exesql();
                break;

            case ProtocolDef.g2e_exesyscmd_def:
                message = new g2e_exesyscmd();
                break;

            case ProtocolDef.g2e_GetGuardDir_def:
                message = new g2e_GetGuardDir();
                break;

            case ProtocolDef.g2e_switchmode_def:
                message = new KProtocolHead();
                break;

            case ProtocolDef.g2e_config_def:
                message = new KProtocolHead();
                break;

            case ProtocolDef.g2e_updateserver_def:
                message = new g2e_updateserver();
                break;

            case ProtocolDef.g2e_ftpdownload_def:
                message = new g2e_ftpdownload();
                break;

            case ProtocolDef.g2e_serverpid_def:
                message = new g2e_server_pid();
                break;
                #endregion

                #region 与游戏的通讯

            case ProtocolDef.l2e_header_def:
            {
                if (msgBuff.Length <= 4)
                {
                    return;
                }
                ProtocolDef subProtocolId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 4);

                switch (subProtocolId)
                {
                // ahpho
                case ProtocolDef.l2e_update_custom_info_def:
                    message = new l2e_update_custom_info();
                    break;

                case ProtocolDef.l2e_PlayerCount_def:
                    message = new l2e_PlayerCount();
                    break;

                case ProtocolDef.l2e_ExeGMCmd_def:
                    message = new l2e_ExeGMCmd();
                    break;

                case ProtocolDef.l2e_GetBasicInfo_def:
                    message = new l2e_GetBasicInfo();
                    break;

                case ProtocolDef.l2e_Who_def:
                    message = new l2e_Who();
                    break;

                case ProtocolDef.l2e_GetGlobalVariable_def:
                    message = new l2e_GetGlobalVariable();
                    break;

                case ProtocolDef.l2e_GetGameStartTime_def:
                    message = new l2e_GetGameStartTime();
                    break;

                case ProtocolDef.l2e_ReportError_def:
                    message = new l2e_ReportError();
                    break;

                case ProtocolDef.l2e_info_def:
                    message = new l2e_info();
                    break;

                case ProtocolDef.l2e_info_large_def:
                    message = new l2e_info_large();
                    break;

                case ProtocolDef.l2e_ping_def:
                    message = new KSubProtocolHead();
                    break;

                default:
                    throw new Exception("收到未在MessageEngine中注册的协议包");
                }
            }
            break;
                #endregion

            default:
                //TODO 记录没有出现过的协议包,开发阶段抛出异常
                throw new Exception("收到未在MessageEngine中注册的协议包");
            }

            if (server != null && message != null)
            {
                message.FromBytes(msgBuff);
                AdminServer.TheInstance.GameServerManager.ProcessMessage(server, message);
            }
        }
예제 #2
0
        private void MessageReceived(GameServer server, IProtocol message)
        {
            ISubProtocol pSubProtocol = message.GetSubProtocol();

            if (pSubProtocol == null ||
                (ProtocolDef)message.ProtocolId != ProtocolDef.l2e_header_def)
            {
                return;
            }
            byte[] data = message.ToBytes();
            switch ((ProtocolDef)pSubProtocol.SubProtocolID)
            {
            // ahpho
            case ProtocolDef.l2e_update_custom_info_def:
            {
                l2e_update_custom_info protocal = new l2e_update_custom_info();
                protocal.FromBytes(data);
                _customInfoStrs = protocal.GetInfoStrs();
            }
            break;

            case ProtocolDef.l2e_PlayerCount_def:
            {
                l2e_PlayerCount protocol = new l2e_PlayerCount();
                protocol.FromBytes(data);
                if (protocol.GetTotalCount() >= 0)
                {
                    UpdatePlayerCount(protocol.GetTotalCount(), server.Group);
                }

                if (protocol.GetOffliveCount() >= 0)
                {
                    UpdateOfflineCount(protocol.GetOffliveCount());
                }
            }
            break;

            //GM指令接收的消息
            case ProtocolDef.l2e_ExeGMCmd_def:
            {
                l2e_ExeGMCmd protocol = new l2e_ExeGMCmd();
                protocol.FromBytes(data);
                //l2e_ExeGMCmd protocol = (l2e_ExeGMCmd)message;
                if (protocol.ReturnCode == 1)
                {
                    UpdateGMResultCache(protocol.nSessionID, protocol.szResult);
                }
                else
                {
                    UpdateGMResultCache(protocol.nSessionID, "GM指令操作失败");
                }
            }
            break;

            case ProtocolDef.l2e_GetBasicInfo_def:
            {
                l2e_GetBasicInfo protocol = new l2e_GetBasicInfo();
                protocol.FromBytes(data);
            }
            break;

            case ProtocolDef.l2e_Who_def:
            {
                l2e_Who protocol = new l2e_Who();
                protocol.FromBytes(data);
                UpdatePlayerWho(protocol.PlayerList);
            }
            break;

            case ProtocolDef.l2e_GetGlobalVariable_def:
            {
                l2e_GetGlobalVariable protocol = new l2e_GetGlobalVariable();
                protocol.FromBytes(data);
                server.GameSetting.UpdateGlobalVariable(protocol.VariableIndex, protocol.VariableValue);
            }
            break;

            case ProtocolDef.l2e_GetGameStartTime_def:
            {
                l2e_GetGameStartTime protocol = new l2e_GetGameStartTime();
                protocol.FromBytes(data);
                int seconds = int.Parse(protocol.GameStartTime);
                _gameRunningRefreshTime = DateTime.Now;
                _gameRunningTime        = new TimeSpan(0, 0, seconds);
            }
            break;

            case ProtocolDef.l2e_ReportError_def:
            {
                l2e_ReportError protocol = new l2e_ReportError();
                protocol.FromBytes(data);
                SetModuleStateCode(protocol.Module, protocol.ErrorCode);
            }
            break;

            case ProtocolDef.l2e_info_def:
            {
                l2e_info protocol = new l2e_info();
                protocol.FromBytes(data);
                Hashtable infoPackage = Util.ConvertKeyValuePairToHashtable(protocol.Info);
                if (infoPackage != null)
                {
                    GameInfoReceived(infoPackage);
                }
            }
            break;

            case ProtocolDef.l2e_info_large_def:
            {
                l2e_info_large protocol = new l2e_info_large();
                protocol.FromBytes(data);
                Hashtable infoPackage = Util.ConvertKeyValuePairToHashtable(protocol.InfoLarge);
                if (infoPackage != null)
                {
                    GameInfoReceived(infoPackage);
                }
            }
            break;
            }
        }
예제 #3
0
파일: LordControl.cs 프로젝트: viticm/pap2
		private void MessageReceived(GameServer server, IProtocol message)
        {
            ISubProtocol pSubProtocol = message.GetSubProtocol();
            if (pSubProtocol == null ||
                (ProtocolDef)message.ProtocolId != ProtocolDef.l2e_header_def)
            {
                return;
            }
            byte[] data = message.ToBytes();
            switch ((ProtocolDef)pSubProtocol.SubProtocolID)
            {
                // ahpho
                case ProtocolDef.l2e_update_custom_info_def:
                    {
                        l2e_update_custom_info protocal = new l2e_update_custom_info();
                        protocal.FromBytes(data);
                        _customInfoStrs = protocal.GetInfoStrs();
                    }
                    break;
                case ProtocolDef.l2e_PlayerCount_def:
                    {
                        l2e_PlayerCount protocol = new l2e_PlayerCount();
                        protocol.FromBytes(data);
                        if (protocol.GetTotalCount() >= 0)
                        {
                            UpdatePlayerCount(protocol.GetTotalCount(),server.Group);                            
                        }

                        if (protocol.GetOffliveCount() >= 0)
                            UpdateOfflineCount(protocol.GetOffliveCount());
                    }
                    break;
                
                //GM指令接收的消息
                case ProtocolDef.l2e_ExeGMCmd_def:
                    {
                        l2e_ExeGMCmd protocol = new l2e_ExeGMCmd();
                        protocol.FromBytes(data);
                        //l2e_ExeGMCmd protocol = (l2e_ExeGMCmd)message;
                        if (protocol.ReturnCode == 1)
                        {
                            UpdateGMResultCache(protocol.nSessionID, protocol.szResult);
                        }
                        else
                        {
                            UpdateGMResultCache(protocol.nSessionID, "GM指令操作失败");
                        }                          
                    }
                    break;
                case ProtocolDef.l2e_GetBasicInfo_def:
                    {
                        l2e_GetBasicInfo protocol = new l2e_GetBasicInfo();
                        protocol.FromBytes(data);
                    }
                    break;
                case ProtocolDef.l2e_Who_def:
                    {
                        l2e_Who protocol = new l2e_Who();
                        protocol.FromBytes(data);
                        UpdatePlayerWho(protocol.PlayerList);
                    }
                    break;
                case ProtocolDef.l2e_GetGlobalVariable_def:
                    {
                        l2e_GetGlobalVariable protocol = new l2e_GetGlobalVariable();
                        protocol.FromBytes(data);
                        server.GameSetting.UpdateGlobalVariable(protocol.VariableIndex, protocol.VariableValue);
                    }
                    break;
                case ProtocolDef.l2e_GetGameStartTime_def:
                    {
                        l2e_GetGameStartTime protocol = new l2e_GetGameStartTime();
                        protocol.FromBytes(data);
                        int seconds = int.Parse(protocol.GameStartTime);
                        _gameRunningRefreshTime = DateTime.Now;
                        _gameRunningTime = new TimeSpan(0, 0, seconds);
                    }
                    break;
                case ProtocolDef.l2e_ReportError_def:
                    {
                        l2e_ReportError protocol = new l2e_ReportError();
                        protocol.FromBytes(data);
                        SetModuleStateCode(protocol.Module, protocol.ErrorCode);
                    }
                    break;
                case ProtocolDef.l2e_info_def:
                    {
                        l2e_info protocol = new l2e_info();
                        protocol.FromBytes(data);
                        Hashtable infoPackage = Util.ConvertKeyValuePairToHashtable(protocol.Info);
                        if (infoPackage != null)
                            GameInfoReceived(infoPackage);
                    }
                    break;
                case ProtocolDef.l2e_info_large_def:
                    {
                        l2e_info_large protocol = new l2e_info_large();
                        protocol.FromBytes(data);
                        Hashtable infoPackage = Util.ConvertKeyValuePairToHashtable(protocol.InfoLarge);
                        if (infoPackage != null)
                            GameInfoReceived(infoPackage);
                    }
                    break;
            }
		}
예제 #4
0
		/// <summary>
		/// 分发消息
		/// </summary>
		/// <param name="msgBuff">消息</param>
		private void Dispatch(GameServer server, byte[] msgBuff)
		{
			if (server == null || msgBuff == null)
				return;

            if (msgBuff.Length <= 2)
            {
                return;
            }


			ProtocolDef protocalId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 0);
			IProtocol message = null;
			switch (protocalId)
			{
				#region 文件管理
				case ProtocolDef.g2e_openfile_def://打开文件
                    message = new g2e_openfile();
                    message.FromBytes(msgBuff);
					break;
				case ProtocolDef.g2e_seekfile_def://移动到文件中的位置
					message = new g2e_seekfile();
					break;
				case ProtocolDef.g2e_writefile_def://写入文件
					message = new g2e_writefile();
					break;
				case ProtocolDef.g2e_closefile_def://关闭文件
					message = new g2e_closefile();
					break;
                case ProtocolDef.g2e_readfile_def: //读文件
                    message = new g2e_readfile();
                    break;
				#endregion

				#region 游戏服务器信息
				case ProtocolDef.g2e_getcpubaseinfo_def://取得CPU基本信息
					message = new g2e_getcpubaseinfo();
					break;
				case ProtocolDef.g2e_getcpuload_def://取得CPU负载
					message = new g2e_getcpuload();
					break;
				case ProtocolDef.g2e_getdiskinfo_def://取得磁盘信息
                    message = new g2e_getdiskinfo();
					break;
				case ProtocolDef.g2e_getmeminfo_def://取得内存信息
                    message = new g2e_getmeminfo();
					break;
				case ProtocolDef.g2e_getprocinfo_def://取得进程信息
                    message = new g2e_getprocinfo();
					break;
				case ProtocolDef.g2e_getcardload_def://取得网卡负载
                    message = new g2e_getcardload();					
					break;
				case ProtocolDef.g2e_getnetinfo_def://取得网卡信息
                    message = new g2e_getnetinfo();
					break;
                case ProtocolDef.g2e_getpluginfo_def://取得插件信息
                    message = new g2e_getpluginfo();
                    break;				
				#endregion

				#region 其他
				case ProtocolDef.g2e_ping_def://Ping
                    message = new KProtocolHead();
                    break;
				case ProtocolDef.g2e_exesql_def:
					message = new g2e_exesql();
					break;
				case ProtocolDef.g2e_exesyscmd_def:
					message = new g2e_exesyscmd();
					break;
				case ProtocolDef.g2e_GetGuardDir_def:
					message = new g2e_GetGuardDir();
					break;
				case ProtocolDef.g2e_switchmode_def:
					message = new KProtocolHead();
					break;
				case ProtocolDef.g2e_config_def:
					message = new KProtocolHead();
					break;
                case ProtocolDef.g2e_updateserver_def:
                    message = new g2e_updateserver();
                    break;
                case ProtocolDef.g2e_ftpdownload_def:
                    message = new g2e_ftpdownload();
                    break;
                case ProtocolDef.g2e_serverpid_def:
                    message = new g2e_server_pid();
                    break;                        
				#endregion

				#region 与游戏的通讯
			
                case ProtocolDef.l2e_header_def:
                    {
                        if (msgBuff.Length <= 4)
                            return;
                        ProtocolDef subProtocolId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 4);

                        switch (subProtocolId)
                        {
                            // ahpho
                            case ProtocolDef.l2e_update_custom_info_def:
                                message = new l2e_update_custom_info();
                                break;
                            case ProtocolDef.l2e_PlayerCount_def:
                                message = new l2e_PlayerCount();
                                break;
                            case ProtocolDef.l2e_ExeGMCmd_def:
                                message = new l2e_ExeGMCmd();
                                break;
                            case ProtocolDef.l2e_GetBasicInfo_def:
                                message = new l2e_GetBasicInfo();
                                break;
                            case ProtocolDef.l2e_Who_def:
                                message = new l2e_Who();
                                break;
                            case ProtocolDef.l2e_GetGlobalVariable_def:
                                message = new l2e_GetGlobalVariable();
                                break;
                            case ProtocolDef.l2e_GetGameStartTime_def:
                                message = new l2e_GetGameStartTime();
                                break;
                            case ProtocolDef.l2e_ReportError_def:
                                message = new l2e_ReportError();
                                break;
                            case ProtocolDef.l2e_info_def:
                                message = new l2e_info();
                                break;
                            case ProtocolDef.l2e_info_large_def:
                                message = new l2e_info_large();
                                break;
                            case ProtocolDef.l2e_ping_def:
                                message = new KSubProtocolHead();
                                break;
                            default:
                                throw new Exception("收到未在MessageEngine中注册的协议包");
                        }
                    }
                    break;
				#endregion

				default:
					//TODO 记录没有出现过的协议包,开发阶段抛出异常
					throw new Exception("收到未在MessageEngine中注册的协议包");
			}

			if (server != null && message != null)
			{
                message.FromBytes(msgBuff);
				AdminServer.TheInstance.GameServerManager.ProcessMessage(server, message);
			}
		}