You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.4 KiB

6 years ago
6 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace Multiplayer
  6. {
  7. public class ServerManager : MonoSingleton<ServerManager>
  8. {
  9. [SerializeField]
  10. private bool StartOnAwake = true;
  11. [SerializeField]
  12. private int Port = 4444;
  13. public long Seed;
  14. public Dictionary<int, Player> AllPlayers;
  15. public NetworkServerSimple Server { get; private set; }
  16. private LoginManager loginManager;
  17. private PlayerServerManager playerManager;
  18. private void Start()
  19. {
  20. if (StartOnAwake)
  21. StartServer();
  22. }
  23. [ContextMenu("Start Server")]
  24. public void StartServer()
  25. {
  26. StartServer(Port);
  27. }
  28. public void StartServer(int Port)
  29. {
  30. this.Port = Port;
  31. AllPlayers = new Dictionary<int, Player>();
  32. Server = new NetworkServerSimple();
  33. Server.Configure(ChannelConfig.DefaultTopology());
  34. Debug.Log("Starting Server on " + Port);
  35. loginManager = new LoginManager(this);
  36. playerManager = new PlayerServerManager(this);
  37. Seed = System.DateTime.Now.Ticks;
  38. Server.Listen(Port);
  39. }
  40. private void Update()
  41. {
  42. if (Server != null)
  43. Server.Update();
  44. }
  45. }
  46. }