/// <summary> /// Initialize MapServer /// </summary> /// <param name="port">Port where the MapServer will run</param> /// <param name="connName">Connection string for connection</param> /// <param name="mapName">Name of the map</param> /// <param name="mapIndex">Index of the map</param> public void Init(int port, string connName, string mapName, int mapIndex) { MapName = mapName; MapIndex = mapIndex; statisticsStopwatch = new Stopwatch(); mobStopwatch = new Stopwatch(); statisticsStopwatch.Start(); mobStopwatch.Start(); statistics = Statistics.None; _netPeerConfig = new NetPeerConfiguration(connName); _netPeerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true); _netPeerConfig.PingInterval = 3f; _netPeerConfig.ConnectionTimeout = 6.5f; //_netPeerConfig.SimulatedMinimumLatency = 0.1f; //_netPeerConfig.SimulatedRandomLatency = 0.01f; _netPeerConfig.Port = (int)port; NetServer = new NetServer(_netPeerConfig); Data = new WorldDataHandler(ServerIndex); OutgoingMessageHandler = new OutgoingMessageHandler(NetServer, Data); IncomingMessageHandler = new IncomingMessageHandler(this); InitTeleporter(new Vector3(450, 0, 450), 2.5f, mapIndex == 0 ? 1 : 0); InitSpawners(mapsFolderPath); Console.WriteLine("Server UP"); ServerUp = true; }
/// <summary> /// Called every server frame in the PlayerUpdateThread /// Calls the Tick() methot for every online PlayerEntity /// Also checks for Disconnected clients /// /// Sends the Movement info to clients of players who changed position in the frame /// </summary> /// <returns></returns> public long PlayerUpdate() { long startMils = statisticsStopwatch.ElapsedMilliseconds; //READ JOB FROM QUE AND HANDLE THAT //Update players foreach (var player in Data.PlayersByUid.Values) { player.Tick(); if (player.Connection != null) { if (player.Connection.Status == NetConnectionStatus.Disconnected) { if (Data.RemovePlayer(player)) { Console.WriteLine($"Player disconnected:\n{player}"); OutgoingMessageHandler.SendDisconnect(player); } } } } OutgoingMessageHandler.SendPlayerMovementInfoByGridCell(); //MessageSender.Instance.SendPlayerMovementInfoByPlayers(); _updateTick++; return(statisticsStopwatch.ElapsedMilliseconds - startMils); }
internal OutgoingMessage(long messageId, OutgoingMessageHandler updateCallback, OutgoingMessageManager messageManager, WaterFlowManager outgoingFlowManager) { this.messageId = messageId; this.updateCallback = updateCallback; this.messageManager = messageManager; this.outgoingFlowManager = outgoingFlowManager; }