private void RealHandleMessage(byte[] messageData) { using (MessageReader mr = new MessageReader(messageData)) { ModpackDataMessageType type = (ModpackDataMessageType)mr.Read <int>(); switch (type) { case ModpackDataMessageType.CKAN: { modpackMode = ModpackMode.CKAN; byte[] receiveData = mr.Read <byte[]>(); byte[] oldData = null; if (File.Exists(ckanDataPath)) { oldData = File.ReadAllBytes(ckanDataPath); } if (!BytesMatch(oldData, receiveData)) { missingWarnFile = true; DarkLog.Debug("Ckan file changed"); File.Delete(ckanDataPath); File.WriteAllBytes(ckanDataPath, receiveData); } if (!registeredChatCommand) { registeredChatCommand = true; chatWorker.RegisterChatCommand("upload", UploadCKANToServer, "Upload DarkMultiPlayer.ckan to the server"); } } break; case ModpackDataMessageType.MOD_LIST: { modFilesToHash = null; modFilesToHashPos = 0; serverPathCache.Clear(); noWarnSha.Clear(); modpackMode = ModpackMode.GAMEDATA; string[] files = mr.Read <string[]>(); string[] sha = mr.Read <string[]>(); if (File.Exists(gameDataServerCachePath)) { File.Delete(gameDataServerCachePath); } using (StreamWriter sw = new StreamWriter(gameDataServerCachePath)) { for (int i = 0; i < files.Length; i++) { bool skipFile = false; foreach (string ignoreString in ignoreList) { if (files[i].ToLower().StartsWith(ignoreString, StringComparison.Ordinal)) { skipFile = true; } } foreach (string ignoreString in containsIgnoreList) { if (files[i].ToLower().Contains(ignoreString)) { skipFile = true; } } if (skipFile) { continue; } sw.WriteLine("{0}={1}", files[i], sha[i]); serverPathCache.Add(files[i], sha[i]); } } LoadAuto(); if (!registeredChatCommand) { registeredChatCommand = true; chatWorker.RegisterChatCommand("upload", UploadToServer, "Upload GameData to the server"); } } break; case ModpackDataMessageType.REQUEST_OBJECT: { modFilesToUpload = mr.Read <string[]>(); modFilesToUploadPos = 0; DarkLog.Debug("Server requested " + modFilesToUpload.Length + " files"); } break; case ModpackDataMessageType.RESPONSE_OBJECT: { string sha256sum = mr.Read <string>(); filesDownloaded++; if (mr.Read <bool>()) { syncString = "Syncing files " + filesDownloaded + "/" + requestList.Count + " (" + (serverPathCache.Count - requestList.Count) + " cached)"; byte[] fileBytes = mr.Read <byte[]>(); string filePath = Path.Combine(cacheDataPath, sha256sum + ".bin"); if (!File.Exists(filePath)) { File.WriteAllBytes(filePath, fileBytes); } } else { ScreenMessages.PostScreenMessage("DMP Server has an out of date hash list. Tell the admin to run /reloadmods", float.PositiveInfinity, ScreenMessageStyle.UPPER_CENTER); networkWorker.Disconnect("Syncing files error"); } if (filesDownloaded == requestList.Count) { if (missingWarnFile) { networkWorker.Disconnect("Syncing files " + filesDownloaded + "/" + requestList.Count + " (" + (serverPathCache.Count - requestList.Count) + " cached)"); ScreenMessages.PostScreenMessage("Please run DMPModpackUpdater or reconnect to ignore", float.PositiveInfinity, ScreenMessageStyle.UPPER_CENTER); } else { synced = true; } } } break; case ModpackDataMessageType.MOD_DONE: { if ((!missingWarnFile && requestList.Count == 0) || secondModSync) { synced = true; } else { if (modpackMode == ModpackMode.CKAN) { ScreenMessages.PostScreenMessage("Please install CKAN update at KSP/DarkMultiPlayer.ckan or reconnect to ignore", float.PositiveInfinity, ScreenMessageStyle.UPPER_CENTER); networkWorker.Disconnect("Synced DarkMultiPlayer.ckan"); } if (modpackMode == ModpackMode.GAMEDATA && requestList.Count == 0) { ScreenMessages.PostScreenMessage("Please run DMPModpackUpdater or reconnect to ignore", float.PositiveInfinity, ScreenMessageStyle.UPPER_CENTER); syncString = "Synced files (" + serverPathCache.Count + " cached)"; networkWorker.Disconnect(syncString); } } secondModSync = true; } break; } } }