当前位置: 首页>>代码示例>>C#>>正文


C# IProtocol.ToBytes方法代码示例

本文整理汇总了C#中IProtocol.ToBytes方法的典型用法代码示例。如果您正苦于以下问题:C# IProtocol.ToBytes方法的具体用法?C# IProtocol.ToBytes怎么用?C# IProtocol.ToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProtocol的用法示例。


在下文中一共展示了IProtocol.ToBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MessageReceived

		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)
//.........这里部分代码省略.........
开发者ID:viticm,项目名称:pap2,代码行数:101,代码来源:LordControl.cs

示例2: SendMessage

		/// <summary>
		/// 发送消息
		/// </summary>
		public bool SendMessage(IProtocol message)
		{            
            if (IsConnected && SendData(message.ToBytes()))
            {
                if (MessageSent != null)
                {
                    MessageSent(this, message);
                }
                return true;
            }
            else
            {
                return false;
            }
		}
开发者ID:viticm,项目名称:pap2,代码行数:18,代码来源:GameServer.cs

示例3: ServerMessageReceived

		void ServerMessageReceived(GameServer server, IProtocol message)
		{
            if ((ProtocolDef)message.ProtocolId == ProtocolDef.l2e_header_def)
            {
                switch ((ProtocolDef)BitConverter.ToUInt16(message.ToBytes(), 4))
                {
                    case ProtocolDef.l2e_GetGlobalVariable_def:
                        {
                            l2e_GetGlobalVariable protocol = message as l2e_GetGlobalVariable;
                            UpdateGlobalVariable(protocol.VariableIndex, protocol.VariableValue);
                        }
                        break;
                    case ProtocolDef.l2e_ping_def:
                        {
                            
                            server.GameServiceState = GameServer.ServiceState.Running;
                            if (server.PID <= 0)
                            {
                                string[] para = new string[1] { server.Id.ToString() };
                                server.DoPlugInAction(SecurityManager.SystemAutomationId, E2gServerPID.PlugInGuid, E2gServerPID.actionKey, para);
                            }
                            break;
                        }
                }
            }
		}
开发者ID:viticm,项目名称:pap2,代码行数:26,代码来源:GameServer.cs

示例4: MessageReceived

		private void MessageReceived(GameServer server, IProtocol message)
		{
            try
            {
                if (message.ToBytes().Length >= 6)
                {
                    switch ((ProtocolDef)BitConverter.ToUInt16(message.ToBytes(), 4))
                    {
                        case ProtocolDef.l2e_ping_def://Ping
                            {
                                _lastPing = DateTime.Now;
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                Util.DebugLog(string.Format("Exception in Server[{0}] PlugIns.cs OnMessageReceived : {1}", this.Name, ex.StackTrace));
            }
			
		}
开发者ID:viticm,项目名称:pap2,代码行数:22,代码来源:PlugIns.cs


注:本文中的IProtocol.ToBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。