public static void SendPlayerChatChannels(ClientStructure client) { var channels = PlayerChatChannels.Select(v => new KeyValuePair <string, string[]>(v.Key, v.Value.ToArray())).ToArray(); MessageQueuer.SendToClient <ChatSrvMsg>(client, new ChatListReplyMsgData { PlayerChannels = channels }); }
public static void TechnologyReceived(ClientStructure client, ShareProgressTechnologyMsgData data) { LunaLog.Debug($"Technology unlocked: {data.TechNode.Id}"); //Send the technology update to all other clients MessageQueuer.RelayMessage <ShareProgressSrvMsg>(client, data); ScenarioDataUpdater.WriteTechnologyDataToFile(data); }
/// <summary> /// Sends a message to all the clients except the one given as parameter that are in the subspace given as parameter /// </summary> public static void RelayMessageToSubspace <T>(ClientStructure exceptClient, IMessageData data, int subspace) where T : IServerMessageBase, new() { var newMessage = GenerateMessage <T>(data); foreach (var otherClient in ServerContext.Clients.Values.Where(c => !Equals(c, exceptClient) && c.Subspace == subspace)) { SendToClient(otherClient, newMessage); } }
/// <summary> /// Sends a message to all the clients except the one given as parameter that are in the same subspace /// </summary> public static void RelayMessageToSubspace <T>(ClientStructure exceptClient, IMessageData data) where T : class, IServerMessageBase { if (data == null) { return; } RelayMessageToSubspace <T>(exceptClient, data, exceptClient.Subspace); }
private static void SendToClient(ClientStructure client, IServerMessageBase msg) { if (msg?.Data == null) { return; } LidgrenServer.SendMessageToClient(client, msg); }
public static void SendAdminList(ClientStructure client) { var newMessage = new AdminListReplyMsgData { Admins = AdminCommands.Retrieve().ToArray() }; MessageQueuer.SendToClient <AdminSrvMsg>(client, newMessage); }
public static void HandleKerbalRemove(ClientStructure client, KerbalRemoveMsgData message) { var kerbalToRemove = message.KerbalName; LunaLog.Debug($"Removing kerbal {kerbalToRemove} from {client.PlayerName}"); FileHandler.FileDelete(Path.Combine(KerbalsPath, $"{kerbalToRemove}.txt")); MessageQueuer.RelayMessage <KerbalSrvMsg>(client, message); }
private static void SendToClient(ClientStructure client, IServerMessageBase msg) { if (msg?.Data == null) { return; } client.SendMessageQueue.Enqueue(msg); }
public override void OnMessageReceived(ClientStructure client, IClientMessageBase messageData) { ChatMsgData chatMsgData = messageData.Data as ChatMsgData; if (chatMsgData != null) { connector.SendToDiscord("[" + chatMsgData.From + "] " + chatMsgData.Text); } }
public static void SendAllLocks(ClientStructure client) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <LockListReplyMsgData>(); msgData.Locks = LockSystem.LockQuery.GetAllLocks().ToArray(); msgData.LocksCount = msgData.Locks.Length; MessageQueuer.SendToClient <LockSrvMsg>(client, msgData); }
public static void ReleasePlayerLocks(ClientStructure client) { var removeList = LockQuery.GetAllPlayerLocks(client.PlayerName); foreach (var lockToRemove in removeList) { LockSystemSender.ReleaseAndSendLockReleaseMessage(client, lockToRemove); } }
private static void SetAndSendHandshakeChallangeMessage(ClientStructure client) { client.Challange = new byte[1024]; new Random().NextBytes(client.Challange); MessageQueuer.SendToClient <HandshakeSrvMsg>(client, new HandshakeChallengeMsgData { Challenge = client.Challange }); }
private static void HandleVesselListRequest(ClientStructure client) { MessageQueuer.SendToClient <VesselSrvMsg>(client, new VesselListReplyMsgData { Vessels = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Vessels")) .Select(Common.CalculateSha256Hash) .ToArray() }); }
/// <summary> /// Sends a message to the given client /// </summary> public static void SendToClient <T>(ClientStructure client, IMessageData data) where T : class, IServerMessageBase { if (data == null) { return; } client?.SendMessageQueue.Enqueue(GenerateMessage <T>(data)); }
private bool CheckUsernameIsReserved(ClientStructure client, string playerName) { if (playerName == "Initial" || playerName == GeneralSettings.SettingsStore.ConsoleIdentifier) { Reason = "Using reserved name"; HandshakeSystemSender.SendHandshakeReply(client, HandshakeReply.InvalidPlayername, Reason); return(false); } return(true); }
private bool CheckPlayerIsBanned(ClientStructure client, string uniqueId) { if (BanPlayerCommand.GetBannedPlayers().Contains(uniqueId)) { Reason = "Banned"; HandshakeSystemSender.SendHandshakeReply(client, HandshakeReply.PlayerBanned, Reason); return(false); } return(true); }
private bool CheckServerFull(ClientStructure client) { if (ClientRetriever.GetActiveClientCount() >= GeneralSettings.SettingsStore.MaxPlayers) { Reason = "Server full"; HandshakeSystemSender.SendHandshakeReply(client, HandshakeReply.ServerFull, Reason); return(false); } return(true); }
private bool CheckWhitelist(ClientStructure client, string playerName) { if (GeneralSettings.SettingsStore.Whitelisted && !WhitelistCommands.Retrieve().Contains(playerName)) { Reason = "Not on whitelist"; HandshakeSystemSender.SendHandshakeReply(client, HandshakeReply.NotWhitelisted, Reason); return(false); } return(true); }
private bool CheckUsernameLength(ClientStructure client, string username) { if (username.Length > GeneralSettings.SettingsStore.MaxUsernameLength) { Reason = $"Username too long. Max chars: {GeneralSettings.SettingsStore.MaxUsernameLength}"; HandshakeSystemSender.SendHandshakeReply(client, HandshakeReply.ServerFull, Reason); return(false); } return(true); }
/// <summary> /// Internal use only - Called when a mod message is received from ClientHandler. /// </summary> public static void OnModMessageReceived(ClientStructure client, string modName, byte[] modData) { lock (EventLock) { if (RegisteredMods.ContainsKey(modName)) { RegisteredMods[modName](client, modData); } } }
private static void SetAndSendHandshakeChallangeMessage(ClientStructure client) { new Random().NextBytes(client.Challenge); var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <HandshakeChallengeMsgData>(); msgData.Challenge = client.Challenge; MessageQueuer.SendToClient <HandshakeSrvMsg>(client, msgData); }
public override void HandleMessage(ClientStructure client, IMessageData message) { var data = (ModMsgData)message; if (data.Relay) { MessageQueuer.RelayMessage <ModSrvMsg>(client, data); } LmpModInterface.OnModMessageReceived(client, data.ModName, data.Data); }
private bool CheckUsernameLength(ClientStructure client, string username) { if (username.Length > 10) { Reason = "User too long. Max: 10"; HandshakeSystemSender.SendHandshakeReply(client, HandshakeReply.SERVER_FULL, Reason); return(false); } return(true); }
public static void HandleKerbalProto(ClientStructure client, KerbalProtoMsgData data) { LunaLog.Debug($"Saving kerbal {data.Kerbal.KerbalName} from {client.PlayerName}"); var path = Path.Combine(KerbalsPath, $"{data.Kerbal.KerbalName}.txt"); FileHandler.WriteToFile(path, data.Kerbal.KerbalData, data.Kerbal.NumBytes); MessageQueuer.RelayMessage <KerbalSrvMsg>(client, data); }
public static void SendAdminList(ClientStructure client) { var admins = AdminCommands.Admins.ToArray(); var newMessage = ServerContext.ServerMessageFactory.CreateNewMessageData <AdminListReplyMsgData>(); newMessage.Admins = admins; newMessage.AdminsNum = admins.Length; MessageQueuer.SendToClient <AdminSrvMsg>(client, newMessage); }
public static void HandleMessage(ClientStructure client, IClientMessageBase message) { var data = (ModMsgData)message.Data; if (data.Relay) { MessageQueuer.RelayMessage <ModSrvMsg>(client, data); } LmpModInterface.OnModMessageReceived(client, data.ModName, data.Data, data.NumBytes); }
/// <summary> /// Whenever a release/acquire lock fails, call this method to relay the correct lock definition to the player /// </summary> private static void SendStoredLockData(ClientStructure client, LockDefinition lockDefinition) { var storedLockDef = LockSystem.LockQuery.GetLock(lockDefinition.Type, lockDefinition.PlayerName, lockDefinition.VesselId, lockDefinition.KerbalName); if (storedLockDef != null) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <LockAcquireMsgData>(); msgData.Lock = storedLockDef; MessageQueuer.SendToClient <LockSrvMsg>(client, msgData); } }
public static void ParseReceivedScenarioData(ClientStructure client, ScenarioBaseMsgData messageData) { var data = (ScenarioDataMsgData)messageData; LunaLog.Debug($"Saving {data.ScenarioCount} scenario modules from {client.PlayerName}"); for (var i = 0; i < data.ScenarioCount; i++) { var scenarioAsConfigNode = Encoding.UTF8.GetString(data.ScenariosData[i].Data, 0, data.ScenariosData[i].NumBytes); ScenarioDataUpdater.RawConfigNodeInsertOrUpdate(data.ScenariosData[i].Module, scenarioAsConfigNode); } }
public static void ParseReceivedScenarioData(ClientStructure client, ScenarioBaseMsgData messageData) { var data = (ScenarioDataMsgData)messageData; LunaLog.Debug($"Saving {data.ScenarioCount} scenario modules from {client.PlayerName}"); for (var i = 0; i < data.ScenarioCount; i++) { var path = Path.Combine(ServerContext.UniverseDirectory, "Scenarios", $"{data.ScenariosData[i].Module}.txt"); FileHandler.WriteToFile(path, data.ScenariosData[i].Data, data.ScenariosData[i].NumBytes); } }
//Write the send times down in SYNC_TIME_REPLY packets public static void RewriteMessage(ClientStructure client, IServerMessageBase message) { try { ((SyncTimeReplyMsgData)message.Data).ServerSendTime = DateTime.UtcNow.Ticks; } catch (Exception e) { LunaLog.Debug("Error rewriting SYNC_TIME packet, Exception " + e); } }