Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 检测词汇重复情况
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, int> GetRepetitiveWordCount(string input, Dictionary <string, int> words)
        {
            var res = DictTools.Clone <Dictionary <string, int> >(words);

            if (!string.IsNullOrWhiteSpace(input) && null != words)
            {
                for (int k = 0; k < input.Length; k++)
                {
                    foreach (var item in words)
                    {
                        var wordLength = item.Key.Length;
                        if (k + wordLength <= input.Length)
                        {
                            var substr = input.Substring(k, wordLength);
                            if (substr == item.Key && words.ContainsKey(item.Key))
                            {
                                res[item.Key] += 1; ///添加一个计数
                            }
                        }
                    }
                }
            }
            return(res);
        }
        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);
        }