protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { var gameOperationRequest = new GameOperationRequest(operationRequest.Parameters); var parameters = new MessageParameters { ChannelId = sendParameters.ChannelId, Encrypted = sendParameters.Encrypted }; switch (operationRequest.OperationCode) { case (byte)ClientOperationCode.Login: { this.RequestFiber.Enqueue(() => this.loginOperationHandler.OnOperationRequest(gameOperationRequest, parameters)); } break; case (byte)ClientOperationCode.Character: { this.RequestFiber.Enqueue(() => this.characterOperationHandler.OnOperationRequest(gameOperationRequest, parameters)); } break; default: { this.SendOperationResponse(gameOperationRequest.ClientId, new GameErrorResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.OperationNotAvailable, }, new MessageParameters()); } break; } }
public void OnOperationRequest(GameOperationRequest operationRequest, MessageParameters parameters) { switch ((GameOperationCode)operationRequest.OperationCode) { case GameOperationCode.LoginUser: { this.ExecUserOperation(() => this.HandleOperationLogin(operationRequest, parameters), operationRequest.ClientId, parameters); } break; case GameOperationCode.CreateUser: { this.ExecUserOperation(() => this.HandleOperationCreateNewUser(operationRequest, parameters), operationRequest.ClientId, parameters); } break; default: { this.peer.SendOperationResponse(operationRequest.ClientId, new GameErrorResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.OperationNotAvailable, }, new MessageParameters()); } break; } }
/// <summary> /// Called when an operation request has been received. /// </summary> /// <remarks>An operation request is sent when a client sends an operation request to the master. So all operation requests are from game clients</remarks> protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { var gameOperationRequest = new GameOperationRequest(operationRequest.Parameters); if (!gameOperationRequest.IsValid) { #if MMO_DEBUG Logger.DebugFormat("[OnOperationRequest]: GameOperationRequest (OpCode={0}) is not valid", operationRequest.OperationCode); #endif return; } ISession session; if (sessions.TryGetValue(gameOperationRequest.ClientId, out session)) { var messageParameters = new MessageParameters { ChannelId = sendParameters.ChannelId, Encrypted = sendParameters.Encrypted }; session.ReceiveOperationRequest(gameOperationRequest, messageParameters); } else { Logger.ErrorFormat("[OnOperationRequest]: Session (Id={0}) cannot be found", gameOperationRequest.ClientId); } }
protected virtual GameOperationResponse HandleOperationLogoutUser(GameOperationRequest operationRequest, MessageParameters parameters) { this.peer.SendOperationRequest(new OperationRequest((byte)ServerOperationCode.KillClient, new KillClient { ClientId = operationRequest.ClientId }), new SendParameters()); return(null); }
protected virtual GameOperationResponse HandleOperationCreateCharacter(GameOperationRequest operationRequest, MessageParameters parameters) { var operation = new CreateCharacter(this.peer.Protocol, operationRequest); if (!operation.IsValid) { return(operation.GetErrorResponse((short)ResultCode.InvalidOperationParameter, operation.GetErrorMessage())); } ThreadPool.QueueUserWorkItem( o => this.ExecUserOperation(() => this.HandleCreateCharacter(operationRequest.ClientId, operation), operationRequest.ClientId, parameters)); return(null); }
public AcceptQuest(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public SpHeal(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public LootAll(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public SelectDialogue(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public EnterWorld(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public CastSpell(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public LeaveGroup(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public MoveActionbarSlot(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
/// <summary> /// Queues an <see cref="GameOperationRequest"/> to be processed /// </summary> public void ReceiveOperationRequest(GameOperationRequest operationRequest, MessageParameters messageParameters) { this.chat.SyncFiber.Enqueue(() => this.OnOperationRequest(operationRequest, messageParameters)); }
private GameOperationResponse HandleOperationSendChat(GameOperationRequest operationRequest) { var operation = new SendChat(server.Protocol, operationRequest); if (!operation.IsValid) { return new GameErrorResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() } } ; switch ((MessageType)operation.MessageType) { case MessageType.Group: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Group); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Guild: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Guild); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Local: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Local); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Trade: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Trade); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Tell: { var receiverName = operation.Receiver; if (string.IsNullOrEmpty(receiverName)) { return(operation.GetErrorResponse((short)ResultCode.PlayerNotFound)); } ChatSession receiver; if (!chat.SessionCache.TryGetSessionBySessionName(receiverName, out receiver)) { return(operation.GetErrorResponse((short)ResultCode.PlayerNotFound)); } // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } receiver.ReceiveTell(this, message); } break; default: { #if MMO_DEBUG _logger.DebugFormat("[HandleOperationSendChat]: Session (Name={0}) sent an unhandled Message (Type={1})", name, (MessageType)operation.MessageType); #endif } break; } return(null); } /// <summary> /// Call this to handle client operation requests /// </summary> void OnOperationRequest(GameOperationRequest operationRequest, MessageParameters messageParameters) { GameOperationResponse response; switch ((GameOperationCode)operationRequest.OperationCode) { case GameOperationCode.SendChat: response = this.HandleOperationSendChat(operationRequest); break; default: response = new GameErrorResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.OperationNotAvailable }; break; } if (response != null) { this.SendOperationResponse(response, messageParameters); } } #endregion #region Helper Methods void DoAddSession() { // adding session to the chat while (!chat.AddSession(this)) { ChatSession exisitingSession; if (chat.SessionCache.TryGetSessionBySessionId(sessionId, out exisitingSession)) { // this shouldn't happen because the master won't let the same player login twice it will disconnect the exisitng player // we are handling it to satisfy Murphy's Law #if MMO_DEBUG _logger.DebugFormat("[DoAddSession]: ChatSession (Name={0}) cannot be added because an existing ChatSession (Name={1}) is found", this.Name, exisitingSession.Name); #endif exisitingSession.Disconnect(); this.Disconnect(); this.Destroy(DestroySessionReason.KickedByExistingSession); return; } } } #endregion }
public UseInventorySlot(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public AddActionbarSpell(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public SendChat(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public DisbandGroup(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public Rotate(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public LogoutUser(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public RemoveFriend(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public DeclineFriendRequest(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public CreateCharacter(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public SpRemoveSpell(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public CloseInteraction(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public SendGroupInvite(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public SpAddGold(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public RetrieveCharacters(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }
public SellItem(IRpcProtocol protocol, GameOperationRequest request) : base(protocol, request) { }