WebsocketCommandFactory.cs 989 B

12345678910111213141516171819202122232425262728293031323334
  1. namespace gameapi.Commands
  2. {
  3. public class WebsocketCommandFactory
  4. {
  5. public WebsocketCommandFactory()
  6. {
  7. }
  8. public IWebsocketCommand Create(string commandString)
  9. {
  10. var keys = commandString.Split(" ");
  11. switch (keys[0])
  12. {
  13. case "connect":
  14. return new ConnectWebsocketCommand(keys);
  15. case "disconnect":
  16. return new DisconnectWebsocketCommand(keys);
  17. case "echo":
  18. return new EchoWebsocketCommand(commandString);
  19. case "ping":
  20. return new PongWebsocketCommand();
  21. case "join":
  22. return new JoinWebsocketCommand(keys);
  23. case "leave":
  24. return new LeaveWebsocketCommand(keys);
  25. case "move":
  26. return new MoveWebsocketCommand(keys);
  27. default:
  28. return new UnknownWebsocketCommand();
  29. }
  30. }
  31. }
  32. }