示例#1
0
文件: GameLoop.cs 项目: aevv/Biscuit
        public void AddClient(GameClient client)
        {
            client.Character.Location = client.Character.GetCharacterLocation(_maps.First().Id);
            _clients.Add(client);

            _maps.First(m => m.Id == client.Character.Location.MapId).AddCharacter(client);
        }
示例#2
0
 public void Join(GameClient client)
 {
     _clients.Add(client);
 }
示例#3
0
 public void RemoveClient(GameClient clientToRemove)
 {
     _clients.Remove(clientToRemove.OnlineId);
     Out.Log(string.Format("Client Manager: Client '{0}'", clientToRemove), withDate: true, newline: false);
     Out.Red(" disconnected.", withDate: false);
 }
示例#4
0
 public void AddClient(GameClient clientToAdd)
 {
     _clients.Add(clientToAdd.OnlineId, clientToAdd);
     Out.Log(string.Format("Client Manager: Client '{0}'", clientToAdd), withDate: true, newline: false);
     Out.Green(" connected.", withDate: false);
 }
示例#5
0
文件: Server.cs 项目: aevv/Biscuit
        public void Listen()
        {
            Out.Log("Beginning server start up...");
            if (_serverListener != null)
            {
                Out.Log("Server startup ", false);

                try
                {
                    _serverListener.Start();
                }
                catch (Exception ex)
                {
                    Out.Red("failed!", withDate: false);
                    LogHandler.Log(ex);
                    return;
                }

                Out.Green("success!", withDate: false);
                Out.Log(string.Format("Listening on {0}", _serverListener.LocalEndpoint));
                Running = true;

                Task.Factory.StartNew(GameLoop);
                Task.Factory.StartNew(InputLoop);

                // Running may be set to false, this will stop connections from being accepted.
                while (Running)
                {
                    try
                    {
                        var c = new GameClient(_serverListener.AcceptTcpClient(), Guid.NewGuid(), _clientManager,
                            _chatManager, _game);
                        _clientManager.AddClient(c);
                    }
                    catch
                    {
                        // TODO: Decide how to handle blocking failure on shut down.
                    }
                }
            }
            else
            {
                Out.Red("Server was not correctly initialised.");
            }
        }
示例#6
0
文件: GameLoop.cs 项目: aevv/Biscuit
 public void RemoveClient(GameClient client)
 {
     if (!_clients.Contains(client)) return;
     _clients.Remove(client);
     foreach (Map m in _maps)
         m.RemoveCharacter(client);
     client.Save();
 }
示例#7
0
文件: Map.cs 项目: aevv/Biscuit
 public void AddCharacter(GameClient client)
 {
     _characters.Add(client);
 }
示例#8
0
文件: Map.cs 项目: aevv/Biscuit
        public void SendToPlayer(GameClient client)
        {
            var loc = client.Character.Location;

            var minX = (((int)loc.X) / 64 / 32) - 3;
            var minY = (((int)loc.Y) / 64 / 32) - 3;

            if (minX < 0)
                minX = 0;
            if (minY < 0)
                minY = 0;

            var maxX = minX + 3;
            var maxY = minY + 3;

            if (maxX > _chunks.GetLength(0))
                maxX = _chunks.GetLength(0);
            if (maxY > _chunks.GetLength(1))
                maxY = _chunks.GetLength(1);

            PacketWriter.WritePacket(new SetMapPacket { Name = Name }, client.Writer);

            for (int x = minX; x < maxX; x++)
            {
                for (int y = minY; y < maxY; y++)
                {
                    foreach (var data in this[x, y].GetDataAsString())
                    {
                        PacketWriter.WritePacket(
                            new GiveChunkPacket { X = x, Y = y, Data = data }, client.Writer);
                    }
                }
            }

            PacketWriter.WritePacket(new FinishMapPacket { X = loc.X, Y = loc.Y }, client.Writer);
        }
示例#9
0
文件: Map.cs 项目: aevv/Biscuit
        public void RemoveCharacter(GameClient client)
        {
            if (_characters.Contains(client))
                _characters.Remove(client);

            foreach (var c in _characters)
                PacketWriter.WritePacketAsync(new RemoveEntityPacket { EntityId = client.OnlineId }, c.Writer);
        }