private void InitializeLatencyMonitor() { try { ServerUdpListener = SystemInfo.GetServerUdpListener(this); } catch (Exception) { WriteTimestampedLogEntry("LatencyMonitor.InitializeLatencyMonitor(): Failed to query server data port, retrying in 10 minutes."); DelayCommand(600.0f, delegate() { InitializeLatencyMonitor(); }); return; } // // Create a dummy object so that we may block on its SyncBlock. // This object forms the lock for CurrentLatency, which we cannot // directly use as boxing a new object would result in a new // SyncBlock for every lock attempt. // CurrentLatencyLock = new int(); // // Create the new UDP socket. This has to be done AFTER we get the // UDP listener, for the get UDP listener code to work, as it finds // the first UDP socket opened by nwn2server. // UdpSocket = new UdpClient(AddressFamily.InterNetwork); // // Set the default address to point to the server's local UDP // listener. // UdpSocket.Connect(ServerUdpListener); ALFA.Database Database = new ALFA.Database(this); LocalServerId = Database.ACR_GetServerID(); // // Start the latency measurement thread and the vault ping thread. // LatencyMeasurementThread = new Thread(LatencyMeasurementThreadRoutine); LatencyMeasurementThread.Start(); VaultPingThread = new Thread(VaultPingThreadRoutine); VaultPingThread.Start(); PollServerLatency(); WriteTimestampedLogEntry(String.Format("LatencyMonitor.InitializeLatencyMonitor(): Latency monitoring initialized on data port {0}.", ServerUdpListener)); }
/// <summary> /// Dispatch the event (in a script context). /// </summary> /// <param name="Script">Supplies the script object.</param> /// <param name="Database">Supplies the database connection.</param> public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database) { // // If the event was for the local server, then don't re-broadcast // it. // if (Database.ACR_GetServerID() == Server.ServerId) { return; } string Message = String.Format( "<c=#FFFF00>Server {0} is now online.</c>", Server.Name); string ChatMessage = "</c>" + Message; foreach (uint PlayerObject in Script.GetPlayers(true)) { PlayerState Player = Script.TryGetPlayerState(PlayerObject); if (Player == null) { continue; } if (!Script.IsCrossServerNotificationEnabled(PlayerObject)) { continue; } if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0) { Script.SendMessageToPC(PlayerObject, Message); } else { Script.SendChatMessage( CLRScriptBase.OBJECT_INVALID, PlayerObject, CLRScriptBase.CHAT_MODE_SERVER, ChatMessage, CLRScriptBase.FALSE); } } #if DEBUG_MODE Script.WriteTimestampedLogEntry(Message); #endif }
public Int32 ScriptMain([In] object[] ScriptParameters, [In] Int32 DefaultReturnCode) { if (LatencyMeasurementThread != null) return DefaultReturnCode; ServerUdpListener = SystemInfo.GetServerUdpListener(this); // // Create a dummy object so that we may block on its SyncBlock. // This object forms the lock for CurrentLatency, which we cannot // directly use as boxing a new object would result in a new // SyncBlock for every lock attempt. // CurrentLatencyLock = new int(); // // Create the new UDP socket. This has to be done AFTER we get the // UDP listener, for the get UDP listener code to work, as it finds // the first UDP socket opened by nwn2server. // UdpSocket = new UdpClient(AddressFamily.InterNetwork); // // Set the default address to point to the server's local UDP // listener. // UdpSocket.Connect(ServerUdpListener); ALFA.Database Database = new ALFA.Database(this); LocalServerId = Database.ACR_GetServerID(); // // Start the latency measurement thread and the vault ping thread. // LatencyMeasurementThread = new Thread(LatencyMeasurementThreadRoutine); LatencyMeasurementThread.Start(); VaultPingThread = new Thread(VaultPingThreadRoutine); VaultPingThread.Start(); PollServerLatency(); return DefaultReturnCode; }
/// <summary> /// Dispatch the event (in a script context). /// </summary> /// <param name="Script">Supplies the script object.</param> /// <param name="Database">Supplies the database connection.</param> public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database) { // // If the event was for a player logging on to the local server, // then don't re-broadcast it. // foreach (uint PlayerObject in Script.GetPlayers(true)) { PlayerState Player = Script.TryGetPlayerState(PlayerObject); if (Player == null) { continue; } if (!Player.CharacterIdsShown.Contains(Character.CharacterId)) { string sPlayerListBox = ""; if (Server.ServerId == Script.GetDatabase().ACR_GetServerID() || Script.GetLocalInt(PlayerObject, "chatselect_expanded") == 0) { if (IsDM == true) { sPlayerListBox = "LocalDMList"; Player.ChatSelectLocalDMsShown += 1; } else { sPlayerListBox = "LocalPlayerList"; Player.ChatSelectLocalPlayersShown += 1; } if (Server.ServerId == Script.GetDatabase().ACR_GetServerID()) { Script.AddListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName, "RosterData=/t \"" + Character.CharacterName + "\"", "", "5=/t \"" + Character.CharacterName + "\" ", ""); } else { if (Player.Flags.HasFlag(PlayerStateFlags.ChatSelectShowLocalPlayersOnlyWhenCollapsed)) { continue; } Script.AddListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName, "RosterData=#t \"" + Character.CharacterName + "\"", "", "5=#t \"" + Character.CharacterName + "\" ", ""); } } else { if (IsDM == true) { sPlayerListBox = "RemoteDMList"; Player.ChatSelectRemoteDMsShown += 1; } else { sPlayerListBox = "RemotePlayerList"; Player.ChatSelectRemotePlayersShown += 1; } Script.AddListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName, "RosterData=#t \"" + Character.CharacterName + "\"", "", "5=#t \"" + Character.CharacterName + "\" ", ""); } Player.CharacterIdsShown.Add(Character.CharacterId); Player.UpdateChatSelectGUIHeaders(); } } if (Database.ACR_GetServerID() == Server.ServerId) { return; } string Message = String.Format( "{0}<c=#FFA500>{1} ({2}) joined {3}.</c>", // <c=Orange...> IsDM ? "<c=#99CCFF>[DM] </c>": "", Character.Name, Character.Player.Name, Server.Name); string ChatMessage = "</c>" + Message; foreach (uint PlayerObject in Script.GetPlayers(true)) { PlayerState Player = Script.TryGetPlayerState(PlayerObject); if (Player == null) { continue; } if (!Script.IsCrossServerNotificationEnabled(PlayerObject)) { continue; } if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0) { Script.SendMessageToPC(PlayerObject, Message); } else { Script.SendChatMessage( CLRScriptBase.OBJECT_INVALID, PlayerObject, CLRScriptBase.CHAT_MODE_SERVER, ChatMessage, CLRScriptBase.FALSE); } } #if DEBUG_MODE Script.WriteTimestampedLogEntry(Message); #endif }