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); }
public void Join(GameClient client) { _clients.Add(client); }
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); }
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); }
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."); } }
public void RemoveClient(GameClient client) { if (!_clients.Contains(client)) return; _clients.Remove(client); foreach (Map m in _maps) m.RemoveCharacter(client); client.Save(); }
public void AddCharacter(GameClient client) { _characters.Add(client); }
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); }
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); }