Example #1
0
        public void OnRecieve(HostRecieveEventArgs e)
        {
            // 日志式输出
            var args = (ServerHostRecieveEventArgs)e;

            if (Server.IsDebug)
            {
                System.Console.WriteLine($"[{Time.GetTimeString()}] --> [{(args.Entity.DataMode ? "D" : "C")}] {e.Content}");
            }

            // 判断业务宿主是否为空
            if (_host == null)
            {
                switch (e.Content)
                {
                // 登录业务
                case "PWD":
                    _host = new Hosts.Pwd(this);
                    break;

                // 操作交互标识业务
                case "SID":
                    // 检测登录状态
                    if (!CheckLogin(e))
                    {
                        return;
                    }
                    _host = new Hosts.Sid(this);
                    break;

                // 设置业务
                case "SET":
                    // 检测登录状态
                    if (!CheckLogin(e))
                    {
                        return;
                    }
                    // 检测存储对象
                    if (!CheckStorageEntity(e))
                    {
                        return;
                    }
                    _host = new Hosts.Set(this);
                    break;

                // 获取业务
                case "GET":
                    // 检测登录状态
                    if (!CheckLogin(e))
                    {
                        return;
                    }
                    // 检测存储对象
                    if (!CheckStorageEntity(e))
                    {
                        return;
                    }
                    _host = new Hosts.Get(this);
                    break;

                default:
                    if (Server.IsDebug)
                    {
                        System.Console.WriteLine($"> 不支持的业务类型:{e.Content}");
                    }
                    break;
                }
            }
            else
            {
                // 存在业务宿主则直接将事件传递给业务宿主
                _host.OnRecieve(e);
            }
        }
Example #2
0
 /// <summary>
 /// 设置为空业务
 /// </summary>
 public void SetHostNone()
 {
     _host = null;
 }