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.

66 lines
1.2 KiB

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