예제 #1
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            //Dictionary<byte, object> data = operationRequest.Parameters;
            //Object intvalue;
            //Object stringvalue;
            //data.TryGetValue(1, out intvalue);
            //data.TryGetValue(2, out stringvalue);
            //MyServer.Log.Info("得到请求的数据" + intvalue.ToString() + "," + stringvalue.ToString());
            //Dictionary<byte, object> responsedata = new Dictionary<byte, object>();
            //responsedata.Add(1, (int)intvalue + 111);
            //responsedata.Add(2, stringvalue.ToString() + "加上服务器响应");
            //OperationResponse operationresponse = new OperationResponse(1);
            //operationresponse.Parameters = responsedata;
            //SendOperationResponse(operationresponse, sendParameters);

            //Dictionary<byte, object> data2 = new Dictionary<byte, object>();
            //data2.Add(1, (int)intvalue + 100000);
            //data2.Add(2, stringvalue.ToString() + "加上事件的数据");
            //EventData eventdata = new EventData(1, data2);
            //SendEvent(eventdata, new SendParameters());
            BaseHandler handler = DictTool.GetValue(MyServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode);

            if (handler != default(BaseHandler))
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                handler = DictTool.GetValue(MyServer.Instance.HandlerDict, OperationCode.Default);
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #2
0
        public void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            BaseHandler handler = DictTool.GetValue(requestDict, (OperationCode)operationRequest.OperationCode);

            if (handler != default(BaseHandler))
            {
                handler.OnOperationRequest(operationRequest, sendParameters, peer);
            }
            else
            {
                handler = DictTool.GetValue(requestDict, OperationCode.Default);
                handler.OnOperationRequest(operationRequest, sendParameters, peer);
            }
        }
예제 #3
0
        //处理客户端请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = DictUtil.GetValue(PosSynServer.Instance.handlerDict,
                                                    (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                handler = DictUtil.GetValue(PosSynServer.Instance.handlerDict, OperationCode.Default);
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #4
0
        //处理客户端的请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(GameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                BaseHandler defaultHandler = DictTool.GetValue <OperationCode, BaseHandler>(GameServer.Instance.HandlerDict, OperationCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            //switch ((RequestCode)operationRequest.OperationCode)//要是code不在枚举范围内呢?应该用const int?
            //{
            //    case RequestCode.Test:
            //        {
            //            GameServer.log.Info("接收到数据:" + operationRequest.Parameters[1]);
            //            OperationResponse opResponse = new OperationResponse((int)RequestCode.Test, operationRequest.Parameters);
            //            SendOperationResponse(opResponse, sendParameters);//该方法仅能在该函数中调用

            //            EventData eData = new EventData(1, operationRequest.Parameters);
            //            SendEvent(eData, new SendParameters());//可以在该类中任意地方调用,服务端主动通知客户端
            //        }
            //        break;
            //    default: break;
            //}
        }
예제 #5
0
        //处理客户端得请求    分发Handler 请求   客户端通过OpCustom发送过来的
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = (BaseHandler)PureDictTool.GetValue <OperationCode, BaseHandler>(PureGameServer._instance.handlerDictionary, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #6
0
        //处理客户端的请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.handlerDict, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                BaseHandler defaultHandler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.handlerDict, OperationCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #7
0
        /// <summary>
        /// 处理客户端的请求
        /// </summary>
        /// <param name="operationRequest"></param>
        /// <param name="sendParameters"></param>
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = DictTool.GetValue(MyGameServer.Instance.HandlerDict, (OperateCode)operationRequest.OperationCode);

            if (handler != null)//如果有这个handler的话就用子handler处理
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else//如果没有handler的话就用默认handler处理
            {
                BaseHandler defaultHandler = DictTool.GetValue(MyGameServer.Instance.HandlerDict, OperateCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #8
0
        /// <summary>
        /// 处理客户端请求
        /// </summary>
        /// <param name="operationRequest"></param>
        /// <param name="sendParameters"></param>
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = MobaServer.Instance.HandlerDict.ExTryGet((OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                MobaServer.LogError(">>>>>>>>> 找不到请求的对应处理 : " +
                                    Enum.GetName(typeof(OperationCode), operationRequest.OperationCode));
            }
        }
예제 #9
0
        //当客户端成功连接服务器时调用

        protected override void OnOperationRequest(Photon.SocketServer.OperationRequest operationRequest, Photon.SocketServer.SendParameters sendParameters)
        {
            //通过opcode获得处理的handler,如果找不到,则使用默认的Handler
            BaseHandler baseHandler = DictTool.GetValue <ResponseCode, BaseHandler>(Main.Instance.HandlerDict, (ResponseCode)operationRequest.OperationCode);

            if (baseHandler != null)
            {
                baseHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                DictTool.GetValue <ResponseCode, BaseHandler>(Main.Instance.HandlerDict, (ResponseCode)ResponseCode.Default)
                .OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
        //客户端向服务器发起的请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            //switch (operationRequest.OperationCode)
            //{
            //    //case 是requestCode.
            //    case 1:
            //        MyGameServer.Log.Info("收到客户端发往服务器端的消息");
            //        //得到客户端发送过来的数据字典
            //        Dictionary<byte, object> ValDic = operationRequest.Parameters;
            //        object intValue; object stringValue;
            //        ValDic.TryGetValue(1, out intValue);
            //        ValDic.TryGetValue(2, out stringValue);
            //        MyGameServer.Log.Info("收到客户端发往服务器端的消息,值为:" + intValue);
            //        MyGameServer.Log.Info("收到客户端发往服务器端的消息,值为:" + stringValue);


            //        //回应
            //        OperationResponse OpResponse = new OperationResponse(1);
            //        Dictionary<byte, object> ValDic2 = new Dictionary<byte, object>();
            //        ValDic2.Add(1, 100);
            //        ValDic2.Add(2, "字符串类型传递");
            //        OpResponse.Parameters = ValDic2;
            //      //向客户端发送回应
            //      SendOperationResponse(OpResponse, sendParameters);


            //        //发送事件
            //        EventData eventData = new EventData(1);
            //        eventData.Parameters = ValDic2;
            //        //直接发送一个事件给客户端,事件可以随时发送,响应只能在客户端发起请求的时候才能给予响应。
            //       SendEvent(eventData, new SendParameters());
            //        break;

            //}
            //根据OpCode查找对应的Handler来进行各自的处理
            OperationCode OpCode      = (OperationCode)operationRequest.OperationCode;
            BaseHandler   baseHandler = MyGameServer.handlerDic.TryGet(OpCode);

            if (baseHandler != null)
            {
                MyGameServer.Log.Info("找到" + OpCode + "对应的Handler,正在进行分配");
                baseHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                MyGameServer.Log.Info("没有找到" + OpCode + "对应的Handler");
            }
        }
예제 #11
0
        //客户端链接上的操作
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            ServerTools.log.Info("A");
            BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(ServerRoot.Instance.handlerDict, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                //这里可以写一个默认的Handler处理
                BaseHandler deafultHandler = DictTool.GetValue <OperationCode, BaseHandler>(ServerRoot.Instance.handlerDict, OperationCode.Default);
                deafultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #12
0
        //操作客户端请求 TODO OnOperationRequest......
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.handlerDic, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                BaseHandler deflaut = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.handlerDic, OperationCode.Unknow);
                deflaut.OnOperationRequest(operationRequest, sendParameters, this);
            }

            /*switch (operationRequest.OperationCode)
             * {
             *  case 1:
             *      MyGameServer.log.Info("收到了一个客户端请求");
             *      Dictionary<byte, object> data = operationRequest.Parameters; //客户端传回的数据参数;
             *
             *      object IntValue;
             *      data.TryGetValue(1, out IntValue);
             *      object StringValue;
             *      data.TryGetValue(2, out StringValue);
             *      MyGameServer.log.Info("得到的参数: " + IntValue.ToString() + "," + StringValue.ToString());
             *
             *      OperationResponse opResponse = new OperationResponse(operationRequest.OperationCode);
             *
             *      Dictionary<byte, object> data2 = new Dictionary<byte, object>(); //所要传递的数据
             *      data2.Add(1, 100);
             *      data2.Add(2, "Server");
             *      opResponse.SetParameters(data2); //向客户端传递数据;
             *      SendOperationResponse(opResponse, sendParameters); //给客户端一个响应 必须有请求,才能有响应;
             *
             *      EventData ed = new EventData(1); //1代表事件代码;
             *      ed.SetParameters(data2);
             *      SendEvent(ed, new SendParameters());  //向客户端发送数据和SendOperationResponse有区别,可以不必有响应;
             *
             *      break;
             *  case 2:
             *
             *      break;
             *
             *  default:
             *      break;
             * }*/
        }
예제 #13
0
        //处理客户端的请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            //MyGameServer.log.Info("收到了一个客户端的请求!!!");
            //根据OperationCode在Handler字典中查找响应的Handler
            BaseHandler handler = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                //调用Handler处理请求
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                //未在Handler字典中查找到相应响应的Handler,默认调用defaultHandler
                BaseHandler defaultHandler = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #14
0
        //处理客户端的请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            log.Info("获取到请求:" + (OperationCode)operationRequest.OperationCode);
            //OperationRequest封装了请求的信息
            //SendParameters 参数,客户端向服务器传递过来的数据

            //通过客户端的OperationCode从HandlerDict里面获取到了需要的Hander
            BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode);

            //如果找到了需要的hander就调用我们hander里面处理请求的方法
            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else//否则我们就使用默认的hander
            {
                BaseHandler defaultHandler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, OperationCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
예제 #15
0
        //处理客户端的请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
                MyGameServer.log.Info("收到了一个请求");
            }
            else
            {
                BaseHandler defaultHandler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, OperationCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }


            //switch (operationRequest.OperationCode)//通过OpCode区分请求
            //{
            //    case 1:
            //        MyGameServer.log.Info("收到了一个客户端的请求");
            //        Dictionary<byte, object> data = operationRequest.Parameters;
            //        object intValue;
            //        data.TryGetValue(1, out intValue);
            //        object stringValue;
            //        data.TryGetValue(2, out stringValue);
            //        MyGameServer.log.Info("得到的参数是" + intValue + stringValue);
            //        OperationResponse opResponse = new OperationResponse(1);
            //        Dictionary<byte, object> data2 = new Dictionary<byte, object>();
            //        data2.Add(1, 100);
            //        data2.Add(2, "Error啊我等哈数据库老大");
            //        opResponse.SetParameters(data2);
            //        SendOperationResponse(opResponse, sendParameters);//给客户端一个响应
            //        EventData ed = new EventData(1); ed.Parameters = data2;
            //        SendEvent(ed, new SendParameters());
            //        break;
            //    case 2:
            //        break;
            //    default:
            //        break;
            //}
        }
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            Dictionary <byte, object> dict = operationRequest.Parameters;

            foreach (object value in dict.Values)
            {
                MasterApplication.log.Info("============RedirectedClientPeer==========:" + value.ToString());
            }

            var contract = new RedirectRepeatResponse();

            const byte masterNodeId = 1;

            // TODO: don't lookup for every operation!
            IPAddress publicIpAddress = PublicIPAddressReader.ParsePublicIpAddress(MasterServerSettings.Default.PublicIPAddress);

            switch (this.NetworkProtocol)
            {
            case NetworkProtocolType.Tcp:
                contract.Address =
                    new IPEndPoint(
                        publicIpAddress, MasterServerSettings.Default.MasterRelayPortTcp + masterNodeId - 1).ToString
                        ();
                break;

            case NetworkProtocolType.WebSocket:
                contract.Address =
                    new IPEndPoint(
                        publicIpAddress, MasterServerSettings.Default.MasterRelayPortWebSocket + masterNodeId - 1).
                    ToString();
                break;

            case NetworkProtocolType.Udp:
                // no redirect through relay ports for UDP... how to handle?
                contract.Address =
                    new IPEndPoint(
                        publicIpAddress, MasterServerSettings.Default.MasterRelayPortUdp + masterNodeId - 1).ToString
                        ();
                break;
            }


            var response = new OperationResponse(operationRequest.OperationCode, contract)
            {
                ReturnCode   = (short)ErrorCode.RedirectRepeat,
                DebugMessage = "redirect"
            };

            BaseHandler handler = DictTools.GetValue <ServerToServer.Operations.OperationCode, BaseHandler>(MasterApplication.Instance.Handlerict, (ServerToServer.Operations.OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                BaseHandler defaultHandler = DictTools.GetValue <ServerToServer.Operations.OperationCode, BaseHandler>(MasterApplication.Instance.Handlerict, ServerToServer.Operations.OperationCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }

            this.SendOperationResponse(response, sendParameters);
        }