Example #1
0
        /// <summary>
        /// Send our flag to the server
        /// </summary>
        public void SendCurrentFlag()
        {
            //If the flag does not come from the LMP folder then skip this
            if (!SettingsSystem.CurrentSettings.SelectedFlag.Contains("LunaMultiPlayer/Flags/"))
            {
                return;
            }

            var flagName     = SettingsSystem.CurrentSettings.SelectedFlag.Substring("LunaMultiPlayer/Flags/".Length);
            var fullFlagPath = CommonUtil.CombinePaths(FlagPath, flagName);

            if (!File.Exists(fullFlagPath))
            {
                return;
            }

            MessageSender.SendMessage(MessageSender.GetFlagMessageData(flagName, fullFlagPath));
        }
Example #2
0
        public void SendFlag(string flagUrl)
        {
            //If it's a default flag skip the sending
            if (DefaultFlags.DefaultFlagList.Contains(flagUrl))
            {
                return;
            }

            //If the flag is owned by someone else don't sync it
            if (ServerFlags.TryGetValue(flagUrl, out var existingFlag) && existingFlag.Owner != SettingsSystem.CurrentSettings.PlayerName)
            {
                return;
            }

            var textureInfo = GameDatabase.Instance.GetTextureInfo(flagUrl);

            if (textureInfo != null)
            {
                var filePath = CommonUtil.CombinePaths(MainSystem.KspPath, "GameData", $"{flagUrl}.png");
                if (!File.Exists(filePath))
                {
                    LunaLog.LogError($"Cannot upload flag {Path.GetFileName(flagUrl)} file not found");
                    return;
                }

                var flagData = File.ReadAllBytes(filePath);
                if (flagData.Length > 1000000)
                {
                    LunaLog.LogError($"Cannot upload flag {Path.GetFileName(flagUrl)} size is greater than 1Mb!");
                    return;
                }

                //Don't send the flag when the SHA sum already matches as that would mean that the server already has it
                if (existingFlag != null && existingFlag.ShaSum == Common.CalculateSha256Hash(flagData))
                {
                    return;
                }

                LunaLog.Log($"[LMP]: Uploading {Path.GetFileName(flagUrl)} flag");
                MessageSender.SendMessage(MessageSender.GetFlagMessageData(flagUrl, flagData));
            }
        }