WebsocketCommandFactory.cs 1.0 KB

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 "echo":
  14. return new EchoWebsocketCommand(commandString);
  15. case "ping":
  16. return new PongWebsocketCommand();
  17. case "join":
  18. return new JoinWebsocketCommand(keys);
  19. case "leave":
  20. return new LeaveWebsocketCommand(keys);
  21. case "move":
  22. return new MoveWebsocketCommand(keys);
  23. case "connect":
  24. return new ConnectWebsocketCommand(keys);
  25. case "disconnect":
  26. return new DisconnectWebsocketCommand(keys);
  27. default:
  28. return new UnknownWebsocketCommand();
  29. }
  30. }
  31. }
  32. }