Esempio n. 1
0
        public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, RedirectedClientPeer peer)
        {
            Dictionary <byte, object> dict = operationRequest.Parameters;

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

            string username = DictTools.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username) as string;
            string password = DictTools.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Password) as string;

            UserManager manager = new UserManager();
            User        user    = manager.GetByUsername(username);

            OperationResponse response = new OperationResponse(operationRequest.OperationCode);

            if (user == null)
            {
                user = new User()
                {
                    Username = username, Password = password
                };
                manager.Add(user);
                response.ReturnCode = (short)ReturnCode.Success;
            }
            else
            {
                response.ReturnCode = (short)ReturnCode.Failed;
            }
            peer.SendOperationResponse(response, sendParameters);
        }
Esempio n. 2
0
        public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, RedirectedClientPeer peer)
        {
            string username = DictTools.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username) as string;
            string password = DictTools.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Password) as string;

            UserManager manager   = new UserManager();
            bool        isSuccess = manager.VerifyUser(username, password);

            OperationResponse response = new OperationResponse(operationRequest.OperationCode);

            if (isSuccess)
            {
                response.ReturnCode = (short)ReturnCode.Success;
                peer.username       = username;
                peer.password       = password;
            }
            else
            {
                response.ReturnCode = (short)ReturnCode.Failed;
            }
            peer.SendOperationResponse(response, sendParameters);
        }
        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);
        }