public ServerChunkManager( TychaiaServer server, IChunkOctreeFactory chunkOctreeFactory, IChunkGenerator chunkGenerator, IChunkSizePolicy chunkSizePolicy) { this.m_Server = server; this.m_ChunkOctreeFactory = chunkOctreeFactory; this.m_ChunkGenerator = chunkGenerator; this.m_ChunkSizePolicy = chunkSizePolicy; this.m_RequestedChunks = new ConcurrentQueue<ChunkRequest>(); this.m_ChunkGenerator.InputDisconnect(); }
public PlayerServerEntity( ITerrainSurfaceCalculator terrainSurfaceCalculator, IServerEntityFactory serverEntityFactory, TychaiaServer server, TychaiaServerWorld serverWorld, MxClient client, int uniqueClientIdentifier) { this.m_TerrainSurfaceCalculator = terrainSurfaceCalculator; this.m_ServerEntityFactory = serverEntityFactory; this.m_Server = server; this.m_ServerWorld = serverWorld; this.m_Client = client; this.m_UniqueClientIdentifier = uniqueClientIdentifier; }
public ServerClientManager( IServerFactory serverFactory, TychaiaServer server, TychaiaServerWorld world, int uniqueID, string initialPlayerName, MxClient client) { this.m_Server = server; this.m_World = world; this.UniqueID = uniqueID; this.PlayerName = initialPlayerName; this.MxClient = client; this.Entities = new List<IServerEntity>(); this.ClientChunkStateManager = serverFactory.CreateClientChunkStateManager(client); }
public void Run(string address, int port) { Console.WriteLine("Creating server on " + port + "..."); var server = new TychaiaServer(port, port + 1); server.StartWorld(this.m_Kernel); // Register the local node with Ninject so that entities and worlds can // gain access to it. this.m_Kernel.Bind<INetworkAPI>().ToMethod(x => server); // Create the GameState. Console.WriteLine("Server is now running."); var pingThread = new Thread(() => this.PingServerList(IPAddress.Parse(address), port)) { IsBackground = true }; pingThread.Start(); // Run the game. while (true) { var start = DateTime.Now; server.Update(); var amount = (1000 / 30) - (int)(DateTime.Now - start).TotalMilliseconds; if (amount > 0) { Thread.Sleep(amount); } else { Console.WriteLine("WARNING: Tick took " + (int)(DateTime.Now - start).TotalMilliseconds + "ms, which is longer than 33ms."); } } // ReSharper disable once FunctionNeverReturns }
public TychaiaServerWorld( IServerEntityFactory serverEntityFactory, IServerFactory serverFactory, IPositionScaleTranslation positionScaleTranslation, IPredeterminedChunkPositions predeterminedChunkPositions, TychaiaServer server, ServerChunkManager serverChunkManager) { this.m_ServerEntityFactory = serverEntityFactory; this.m_ServerFactory = serverFactory; this.m_PositionScaleTranslation = positionScaleTranslation; this.m_PredeterminedChunkPositions = predeterminedChunkPositions; this.m_Server = server; this.m_ConnectedClients = new Dictionary<MxClient, ServerClientManager>(); this.m_UniqueIDIncrementer = 1; // TODO: Move server chunk manager into entities list. this.m_ServerChunkManager = serverChunkManager; this.m_Server.ListenForMessage("user input", this.OnUserInput); this.m_Server.ListenForMessage( "join", (client, playerName) => { // The client will repeatedly send join messages until we confirm. if (this.m_ConnectedClients.ContainsKey(client)) { return; } var uniqueID = this.m_UniqueIDIncrementer++; Console.WriteLine("Detected \"" + Encoding.ASCII.GetString(playerName) + "\" has joined"); this.m_Server.SendMessage("join confirm", BitConverter.GetBytes(uniqueID)); var manager = this.m_ServerFactory.CreateServerClientManager( this, this.m_Server, uniqueID, Encoding.ASCII.GetString(playerName), client); this.m_ConnectedClients.Add( client, manager); this.AddPlayer(client, Encoding.ASCII.GetString(playerName)); }); server.ListenForMessage( "change name", (client, newPlayerName) => { // Check to make sure this client is joined. if (!this.m_ConnectedClients.ContainsKey(client)) { return; } var existingName = this.m_ConnectedClients[client].PlayerName; var newName = Encoding.ASCII.GetString(newPlayerName); this.m_ConnectedClients[client].PlayerName = newName; Console.WriteLine("\"" + existingName + "\" has changed their name to \"" + newName + "\""); this.ChangePlayerName(client, newName); }); }