public void Execute <T>(ServerConnection <T> connection, IServerCommand entity) { var leaveRequest = (LeaveRequest)entity; var leaveResponse = new LeaveResponse(); List <PeerBase> connections; if (ServerGameBaseServerPlugin.UsersInScenes.TryGetValue(leaveRequest.GameName, out connections)) { var connInGame = connections.FirstOrDefault(x => x == connection.Peer); if (connInGame != null) { leaveResponse.IsOk = true; ServerGameBaseServerPlugin.RaiseGameLeft(connInGame); connections.Remove(connInGame); } leaveResponse.OperationDetails = "User not in game"; } else { leaveResponse.OperationDetails = "Game not found"; } leaveResponse.ConnectionId = connection.ConnectionId; var cmd = BinaryProtocolHelper <LeaveResponse> .GetProtocol(leaveResponse); connection.SendData(cmd); ServerGameBaseServerPlugin.SendToGamePlayers(leaveRequest.GameName, cmd); }
/// <summary> /// Execute ServerCommand based on Command Type /// </summary> /// <param name="handlerId">Handler for which command is to be executed</param> /// <param name="command">Type of the command to be executed</param> private void ExecuteCommand(string handlerId, string command) { ServerCommandContext commandContext = new ServerCommandContext(Services, handlerId, command); IServerCommand serverCommand = _commandFactory.GetCommand(commandContext); serverCommand.Execute(); }
public void SendCommand(IServerCommand command) { StringBuilder sb = new StringBuilder(); // Sender sb.Append(IRCServer.PREFIX); IUser sender = command.Sender; if (sender != null) { sb.Append(sender.GetIRCName()); sb.Append('!'); sb.Append(sender.UserName); sb.Append('@'); } sb.Append(Server.ServerHost); sb.Append(' '); // Command sb.Append(command.CommandName); sb.Append(' '); // Contents sb.Append(command.GetLine()); sb.Append(IServerCommand.CRLF); Send(sb); }
void ProcessServerCommand(IServerCommand serverCommand) { switch (serverCommand.Command) { case ServerControlCommands.LoadConfiguraiton: var workflowLoader = ServerObjectFactory.Resolve<WorkflowLoader>(); workflowLoader.Load(serverCommand.Data); break; case ServerControlCommands.ResetFull: ServerControl.Reset(); break; case ServerControlCommands.Stop: ServerControl.Stop(); break; case ServerControlCommands.ResetClients: ClientsCollection.Clients = new List<ITestClient>(); break; case ServerControlCommands.ResetAllocatedTasks: TaskPool.TasksForClients = new List<ITestTask>(); break; case ServerControlCommands.ResetLoadedTasks: TaskPool.Tasks = new List<ITestTask>(); break; case ServerControlCommands.ResetWorkflows: WorkflowCollection.Workflows = new List<ITestWorkflow>(); break; // case ServerControlCommands.ExportTestResults: // TmxHelper.ExportResultsToXML(new SearchCmdletBaseDataObject { FilterAll = true }, serverCommand.Data); // break; } }
public ServerControlModule() : base(UrlList.ServerControl_Root) { Put[UrlList.ServerControlPoint_relPath] = _ => { IServerCommand serverCommand = this.Bind <ServerCommand>(); ProcessServerCommand(serverCommand); return(HttpStatusCode.OK); }; }
private static ServerCommandDto Map(IServerCommand c) { if (c.Type == H.Get <IEnterCityServerCommand>()) { return(Map(Cast <IEnterCityServerCommand>(c))); } throw new Exception($"Unexpexted client command type='{c.Type}'"); }
public ServerThreadCommand(IServiceLocator services, IConsoleWriter writer, IServerCommand initServerCommand) { _services = services; _writer = writer; _initServerCommand = initServerCommand; _methodHandlers = _services.Get <IChannelMethodHandlerCollection>(); }
public void Execute <T>(ServerConnection <T> connection, IServerCommand entity) { var loginValue = entity as LogInRequest; var response = new LogInResponse { IsOk = true }; var protocol = BinaryProtocol.FromData(response, new ProtoBufGenericSerializer <LogInResponse>()); connection.SendData(protocol); }
public void Execute <T>(ServerConnection <T> connection, IServerCommand entity) { var cmd = (MessageRequest)entity; var response = new MessageResponse { Message = cmd.Message }; var data = BinaryProtocolHelper <MessageResponse> .GetProtocol(response).Data; PixonicServerPlugin.LastRoomAction[cmd.RoomName] = DateTime.UtcNow; GameBasePlugin.ServerGameBaseServerPlugin.SendToGamePlayers(RoomName, new BinaryProtocol(data, "MessageResponse")); }
public override bool Run() { #region IServerCommand socketcommand = ProtocolRule.GetServerCommand(userData._SourceData); socketcommand._SourceClient = this._clientSocket; //此处需要将sourcedata进行验证,解码后的数据只包括业务数据(???) socketcommand._AfterDecodeData = userData._SourceData; socketcommand._AfterDecodeData.RemoveAt(0); socketcommand._AfterDecodeData.RemoveAt(0); socketcommand._AfterDecodeData.RemoveAt(socketcommand._AfterDecodeData.Count - 1); return(socketcommand.Analysis()); #endregion }
public async Task <T> RunCommandAsync <T>(IServerCommand <T> command) { await _semaphore.WaitAsync(); try { if (command.CanExecute(_gameServer)) { return(await command.ExecuteAsync(_gameServer)); } } finally { _semaphore.Release(); } return((T) default);
public static void ExecuteCommand(IServerCommand serverCommand) { switch (serverCommand) { case ServerCommand.FullState command: onFullState?.Invoke(command); break; case ServerCommand.InvalidPlayerInfo command: onInvalidPlayerInfo?.Invoke(command); break; case ServerCommand.Unknown command: onUnknown?.Invoke(command); break; } }
private bool HandleCommand(string fullString, out string runMessage, IServerCommand command) { bool returnBool; switch (command.Type) { case CommandType.NoParameters: returnBool = command.Run(LoggerManager, AllPlayers, null, out runMessage); break; case CommandType.Parameters: //command is CommandName "param" "param" fullString = CommandName(fullString, command.CommandName + " "); //command is now "param" "param" et.c var parameters = new List <string>(); fullString.Insert(fullString.Length, " "); int lastPos = 0; for (int i = 0; i < command.ParameterCount; i++) { var spaceIndex = fullString.IndexOf(" "); parameters.Add(fullString.Substring(lastPos, spaceIndex)); fullString = fullString.Substring(spaceIndex + 1, fullString.Length); lastPos = parameters[i].Length; } returnBool = command.Run(LoggerManager, AllPlayers, parameters, out runMessage); return(returnBool); case CommandType.Bool: //command is CommandName "param" "param" fullString = CommandName(fullString, command.CommandName + " "); //command is now "param" "param" et.c var parameters2 = new List <string>(); fullString.Insert(fullString.Length, " "); var spaceIndex2 = fullString.IndexOf(" "); parameters2.Add(fullString.Substring(0, spaceIndex2)); returnBool = command.Run(LoggerManager, AllPlayers, parameters2, out runMessage); return(returnBool); default: throw new ArgumentOutOfRangeException(); } runMessage = ""; return(false); }
/// <inheritdoc /> public Task ExecuteAsync(IServerCommand serverCommand, CancellationToken cancellationToken) { var serverCommandType = serverCommand.GetType(); if (!_serverCommandHandlerInfo.TryGetValue(serverCommandType, out var commandHandlerInfo)) { var handlerType = typeof(IServerCommandHandler <>).MakeGenericType(serverCommandType); var executeAsyncMethod = handlerType.GetRuntimeMethod("ExecuteAsync", new[] { serverCommandType, typeof(CancellationToken) }); var handler = _ftpConnectionAccessor.FtpConnection.ConnectionServices.GetRequiredService(handlerType); commandHandlerInfo = new CommandHandlerInfo(handler, executeAsyncMethod); _serverCommandHandlerInfo.Add(serverCommandType, commandHandlerInfo); } return((Task)commandHandlerInfo.ExecuteMethodInfo.Invoke( commandHandlerInfo.CommandHandler, new object[] { serverCommand, cancellationToken })); }
/// <summary> /// Register all the server commands existing in the specified assembly. /// </summary> private void RegisterServerCommands() { // Clear the registered command for it // will raise exception if we are going // to register the command more than once. serverCommands__.Clear(); // Finds all the commands in the specified assembly // and registers them in the hashtable. foreach (Type type in commandAssembly__.GetTypes()) { if (type.IsClass && type.GetInterface("SunnyChen.Common.Servers.IServerCommand") != null) { IServerCommand command = (IServerCommand)Activator.CreateInstance(type); serverCommands__.Add(command.CommandIdentifier, command); } } }
protected override void checkForMessage() { Message message = new Message(); ReadWriteResult result = m_serviceClientQueue.Receive(message); //ReadWriteResult result = ReadWriteResult.OK; IServerCommand clMethod = null; if (result == ReadWriteResult.OK) { string data = Encoding.UTF8.GetString(message.MessageBytes, 0, message.MessageBytes.GetLength(0)); //string data = "{ \"Name\": \"registerClient\", \"PrinterID\": \"\", \"rhoString\": \"manual_common_spec\" }"; Logger.Write("[manager] receive data from client: " + data); clMethod = (IServerCommand)m_methodSelector.selectMethod(data); } processMessage(clMethod); }
/// <summary> /// Registers a command with the server. /// Exceptions: /// <exception cref="CommandAlreadyExistsException">CommandAlreadyExistsException</exception> /// </summary> /// <param name="command">The <see cref="IServerCommand">Command</see> to register.</param> public void RegisterCommand(ICommand command) { if (command is IServerCommand) { foreach (IServerCommand cmd in Commands) { if (cmd.Name == command.Name) { throw new CommandAlreadyExistsException("A command with the same name already exists!"); } else if (cmd.Shortcut == command.Shortcut && !string.IsNullOrEmpty(cmd.Shortcut)) { throw new CommandAlreadyExistsException("A command with the same shortcut already exists!"); } } IServerCommand Cmd = command as IServerCommand; Cmd.ServerCommandHandler = this; Commands.Add(Cmd); } }
/// <inheritdoc /> public Task ExecuteAsync(IServerCommand serverCommand, CancellationToken cancellationToken) { var serverCommandType = serverCommand.GetType(); if (!_serverCommandHandlerDelegates.TryGetValue(serverCommandType, out var cmdDelegate)) { var handlerType = typeof(IServerCommandHandler <>).MakeGenericType(serverCommandType); var executeAsyncMethod = handlerType.GetRuntimeMethod("ExecuteAsync", new[] { serverCommandType, typeof(CancellationToken) }); var handler = _ftpConnectionAccessor.FtpConnection.ConnectionServices.GetRequiredService(handlerType); var commandParameter = Expression.Parameter(serverCommandType, "serverCommand"); var cancellationTokenParameter = Expression.Parameter(typeof(CancellationToken), "cancellationToken"); var call = Expression.Call( Expression.Constant(handler), executeAsyncMethod, commandParameter, cancellationTokenParameter); var expr = Expression.Lambda(call, commandParameter, cancellationTokenParameter); cmdDelegate = expr.Compile(); _serverCommandHandlerDelegates.Add(serverCommandType, cmdDelegate); } return((Task)cmdDelegate.DynamicInvoke(serverCommand, cancellationToken) !); }
void ProcessServerCommand(IServerCommand serverCommand) { switch (serverCommand.Command) { case ServerControlCommands.LoadConfiguraiton: var workflowLoader = ServerObjectFactory.Resolve <WorkflowLoader>(); workflowLoader.Load(serverCommand.Data); break; case ServerControlCommands.ResetFull: ServerControl.Reset(); break; case ServerControlCommands.Stop: ServerControl.Stop(); break; case ServerControlCommands.ResetClients: ClientsCollection.Clients = new List <ITestClient>(); break; case ServerControlCommands.ResetAllocatedTasks: TaskPool.TasksForClients = new List <ITestTask>(); break; case ServerControlCommands.ResetLoadedTasks: TaskPool.Tasks = new List <ITestTask>(); break; case ServerControlCommands.ResetWorkflows: WorkflowCollection.Workflows = new List <ITestWorkflow>(); break; // case ServerControlCommands.ExportTestResults: // TmxHelper.ExportResultsToXML(new SearchCmdletBaseDataObject { FilterAll = true }, serverCommand.Data); // break; } }
public void Execute <T>(ServerConnection <T> connection, IServerCommand entity) { var joinCmd = (JoinRequest)entity; List <PeerBase> peersList; if (ServerGameBaseServerPlugin.UsersInScenes.TryGetValue(joinCmd.GameName, out peersList)) { if (!peersList.Contains(connection.Peer)) { peersList.Add(connection.Peer); var cmd = new JoinResponse { IsOk = true, ConnectionId = connection.ConnectionId }; var response = BinaryProtocolHelper <JoinResponse> .GetProtocol(cmd); connection.SendData(response); ServerGameBaseServerPlugin.SendToGamePlayers(joinCmd.GameName, response); ServerGameBaseServerPlugin.RaiseGameJoin(connection.Peer); } } }
public void SendToClient(IServerCommand command) { lock (_fakeServerCommands) _fakeServerCommands.Enqueue(command); }
public void Execute <T>(ServerConnection <T> serverConnection, IServerCommand entity) { }
public ServerCommandEventArgs(Server server, IServerCommand command, string[] tokens) : base(server) { Command = command; Tokens = tokens; }
private void ProcessCommand(IServerCommand cmd, string[] paramList) { Task.Run(() => cmd.Execute(paramList)); }
private void sendCommand(IServerCommand command) { socket.Emit(command.GetType().Name, new JSONObject(command.ToJsonString())); }
public void processMessage(IServerCommand clMethod) { clMethod.executeCommand(this); }
public ServerCommandEventArgs(IServer server, IServerCommand command, string[] tokens) : base(server) { Command = command; Tokens = tokens; }
public void processMessage(IServerCommand clMethod) { clMethod.executeCommand(this); }