コード例 #1
0
ファイル: Room.cs プロジェクト: Trainfire/Drawesome
        public Room(ConnectionsHandler connections, Player owner, SettingsLoader settings, string password = "")
        {
            ConnectionsHandler = connections;
            connections.AddMessageListener(this);

            Settings = settings;
            Settings.OnSettingsChanged += OnSettingsChanged;

            Owner = owner;

            RoomIdPool = new IdPool(MaxPlayers);

            RoomData = new RoomData();
            RoomData.ID = Guid.NewGuid().ToString().Substring(0, GuidSize);
            RoomData.Password = password;
            RoomData.Players = new List<PlayerData>();
            RoomData.Owner = Owner.Data;
            RoomData.MinPlayers = settings.Values.Server.MinPlayers;

            Players = new List<Player>();

            if (string.IsNullOrEmpty(password))
            {
                Logger.Log(this, "Creating room for {0}", Owner.Data.Name);
            }
            else
            {
                Logger.Log(this, "Creating room for {0} with password {1}", Owner.Data.Name, password);
            }

            Join(Owner);
        }
コード例 #2
0
ファイル: Room.cs プロジェクト: Trainfire/Drawesome
        public Room(ConnectionsHandler connections, Player owner, SettingsLoader settings, string password = "")
        {
            ConnectionsHandler = connections;
            connections.AddMessageListener(this);

            Settings = settings;
            Settings.OnSettingsChanged += OnSettingsChanged;

            Owner = owner;

            RoomIdPool = new IdPool(MaxPlayers);

            RoomData            = new RoomData();
            RoomData.ID         = Guid.NewGuid().ToString().Substring(0, GuidSize);
            RoomData.Password   = password;
            RoomData.Players    = new List <PlayerData>();
            RoomData.Owner      = Owner.Data;
            RoomData.MinPlayers = settings.Values.Server.MinPlayers;

            Players = new List <Player>();

            if (string.IsNullOrEmpty(password))
            {
                Logger.Log(this, "Creating room for {0}", Owner.Data.Name);
            }
            else
            {
                Logger.Log(this, "Creating room for {0} with password {1}", Owner.Data.Name, password);
            }

            Join(Owner);
        }
コード例 #3
0
ファイル: RoomManager.cs プロジェクト: Trainfire/Drawesome
 public RoomManager(ConnectionsHandler connectionHandler, SettingsLoader settings)
 {
     Rooms = new List<Room>();
     SettingsLoader = settings;
     ConnectionsHandler = connectionHandler;
     ConnectionsHandler.AddMessageListener(this);
 }
コード例 #4
0
 public RoomManager(ConnectionsHandler connectionHandler, SettingsLoader settings)
 {
     Rooms              = new List <Room>();
     SettingsLoader     = settings;
     ConnectionsHandler = connectionHandler;
     ConnectionsHandler.AddMessageListener(this);
 }
コード例 #5
0
ファイル: Server.cs プロジェクト: Trainfire/Drawesome
        public void Start()
        {
            Logger.Log(this, "Started");

            Active = true;

            SocketServer = new WebSocketServer(SettingsLoader.Values.Server.HostUrl);
            ConnectionsHandler = new ConnectionsHandler(SettingsLoader);
            RoomManager = new RoomManager(ConnectionsHandler, SettingsLoader);

            SocketServer.Start(socket =>
            {
                socket.OnOpen += () => ConnectionsHandler.OnOpen(socket);
                socket.OnClose += () => ConnectionsHandler.OnClose(socket);
            });

            while (Active)
            {
                CommandHandler.ParseCommand(Console.ReadLine());
            }
        }
コード例 #6
0
ファイル: Server.cs プロジェクト: Trainfire/Drawesome
        public void Start()
        {
            Logger.Log(this, "Started");

            Active = true;

            SocketServer       = new WebSocketServer(SettingsLoader.Values.Server.HostUrl);
            ConnectionsHandler = new ConnectionsHandler(SettingsLoader);
            RoomManager        = new RoomManager(ConnectionsHandler, SettingsLoader);

            SocketServer.Start(socket =>
            {
                socket.OnOpen  += () => ConnectionsHandler.OnOpen(socket);
                socket.OnClose += () => ConnectionsHandler.OnClose(socket);
            });

            while (Active)
            {
                CommandHandler.ParseCommand(Console.ReadLine());
            }
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: Trainfire/Drawesome
 public void Update(ConnectionsHandler manager)
 {
     Console.WriteLine("Send update to " + Data.Name);
 }
コード例 #8
0
ファイル: Player.cs プロジェクト: Trainfire/Drawesome
 public void Update(ConnectionsHandler manager)
 {
     Console.WriteLine("Send update to " + Data.Name);
 }
コード例 #9
0
ファイル: Room.cs プロジェクト: Trainfire/Drawesome
        void OnPlayerConnectionClosed(object sender, PlayerConnectionClosed e)
        {
            // Remove callbacks
            e.Player.OnConnectionClosed  -= OnPlayerConnectionClosed;
            e.Player.OnAwayStatusChanged -= OnPlayerAwayStatusChanged;

            // Inform players
            switch (e.CloseReason)
            {
            case PlayerCloseReason.Disconnected:
                EchoActionToAll(e.Player.Data, PlayerAction.Disconnected);
                break;

            case PlayerCloseReason.Left:
                EchoActionToAll(e.Player.Data, PlayerAction.Left);
                break;

            case PlayerCloseReason.Kicked:
                EchoActionToAll(e.Player.Data, PlayerAction.Kicked);
                break;

            default:
                break;
            }

            // Remove player
            var data = RoomData.Players.Find(x => x.ID == e.Player.Data.ID);

            RoomData.Players.Remove(data);
            Players.Remove(e.Player);

            // Return color to pool
            RoomIdPool.ReturnValue(e.Player.Data.RoomId);

            if (Players.Count != 0)
            {
                // Assign a new owner
                if (Owner != Players[0])
                {
                    Owner          = Players[0];
                    RoomData.Owner = Owner.Data;
                    EchoActionToAll(Owner.Data, PlayerAction.PromotedToOwner);
                }

                if (Players.Count < Settings.Values.Server.MinPlayers)
                {
                    CancelCountdown();
                }

                SendUpdateToAll();
            }
            else
            {
                // Remove room if no players remain
                if (Game != null)
                {
                    Game.End();
                }

                if (CountdownTimer != null)
                {
                    CountdownTimer.Stop();
                }

                Logger.Log(this, "Closing room {0} as it is empty", RoomData.ID);

                ConnectionsHandler.RemoveMessageListener(this);

                if (OnEmpty != null)
                {
                    OnEmpty(this, this);
                }
            }
        }