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); }
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); }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, RedirectedClientPeer peer) { throw new NotImplementedException(); }
public abstract void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, RedirectedClientPeer peer);
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, RedirectedClientPeer peer) { //取得在线客户,不包括当前用户 List <string> usernameList = new List <string>(); foreach (RedirectedClientPeer tempPeer in MasterApplication.Instance.peerList) { if (string.IsNullOrEmpty(tempPeer.username) == false && tempPeer != peer) { usernameList.Add(tempPeer.username); } } //存储字符串 StringWriter sw = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(List <string>)); serializer.Serialize(sw, usernameList); sw.Close(); string usernameListString = sw.ToString(); Dictionary <byte, object> data = new Dictionary <byte, object>(); data.Add((byte)ParameterCode.UsernameKey, usernameListString); OperationResponse response = new OperationResponse(operationRequest.OperationCode); response.Parameters = data; peer.SendOperationResponse(response, sendParameters); foreach (RedirectedClientPeer tempPeer in MasterApplication.Instance.peerList) { if (string.IsNullOrEmpty(tempPeer.username) == false && tempPeer != peer) { EventData ed = new EventData((byte)EventCode.NewPlayer); Dictionary <byte, object> data2 = new Dictionary <byte, object>(); data2.Add((byte)ParameterCode.Username, peer.username); ed.Parameters = data2; tempPeer.SendEvent(ed, sendParameters); } } }