diff --git a/build.gradle.kts b/build.gradle.kts index 70e94a944..2d28772e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { application idea java - kotlin("jvm") version "1.3.70" + kotlin("jvm") version "1.3.72" id("com.github.johnrengelman.shadow") version "5.2.0" id("org.javamodularity.moduleplugin") version "1.5.0" id("org.beryx.jlink") version "2.17.2" @@ -96,6 +96,12 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).configure } } +tasks.create("runDebug") { + enableAssertions = true + classpath = sourceSets.main.get().runtimeClasspath + main = "com.projectswg.holocore.ProjectSWG" +} + tasks.create("CreateConvertLoginJar") { archiveBaseName.set("ConvertLogin") archiveClassifier.set(null as String?) diff --git a/pswgcommon b/pswgcommon index a467fa58c..1c2b23490 160000 --- a/pswgcommon +++ b/pswgcommon @@ -1 +1 @@ -Subproject commit a467fa58c49f16a1aaad1fd2e12f22a99f750103 +Subproject commit 1c2b234908c1c3445b76cbf2712236ab8ef377bc diff --git a/src/main/java/com/projectswg/holocore/intents/support/global/chat/SystemChatRoomMessageIntent.java b/src/main/java/com/projectswg/holocore/intents/support/global/chat/SystemChatRoomMessageIntent.java index 87b66ae51..36532ffb2 100644 --- a/src/main/java/com/projectswg/holocore/intents/support/global/chat/SystemChatRoomMessageIntent.java +++ b/src/main/java/com/projectswg/holocore/intents/support/global/chat/SystemChatRoomMessageIntent.java @@ -26,21 +26,22 @@ ***********************************************************************************/ package com.projectswg.holocore.intents.support.global.chat; +import com.projectswg.holocore.resources.support.global.chat.AdminChatRooms; import me.joshlarson.jlcommon.control.Intent; import org.jetbrains.annotations.NotNull; public class SystemChatRoomMessageIntent extends Intent { - private final String roomPath; + private final AdminChatRooms roomPath; private final String message; - public SystemChatRoomMessageIntent(@NotNull String roomPath, @NotNull String message) { + public SystemChatRoomMessageIntent(@NotNull AdminChatRooms roomPath, @NotNull String message) { this.roomPath = roomPath; this.message = message; } @NotNull - public String getRoomPath() { + public AdminChatRooms getRoomPath() { return roomPath; } @@ -49,7 +50,7 @@ public class SystemChatRoomMessageIntent extends Intent { return message; } - public static void broadcast(@NotNull String roomPath, @NotNull String message) { + public static void broadcast(@NotNull AdminChatRooms roomPath, @NotNull String message) { new SystemChatRoomMessageIntent(roomPath, message).broadcast(); } } diff --git a/src/main/java/com/projectswg/holocore/resources/support/global/chat/AdminChatRooms.kt b/src/main/java/com/projectswg/holocore/resources/support/global/chat/AdminChatRooms.kt new file mode 100644 index 000000000..4d304f0b1 --- /dev/null +++ b/src/main/java/com/projectswg/holocore/resources/support/global/chat/AdminChatRooms.kt @@ -0,0 +1,35 @@ +/*********************************************************************************** + * Copyright (c) 2020 /// Project SWG /// www.projectswg.com * + * * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * + * Our goal is to create an emulator which will provide a server for players to * + * continue playing a game similar to the one they used to play. We are basing * + * it on the final publish of the game prior to end-game events. * + * * + * This file is part of Holocore. * + * * + * --------------------------------------------------------------------------------* + * * + * Holocore is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * Holocore is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with Holocore. If not, see . * + ***********************************************************************************/ + +package com.projectswg.holocore.resources.support.global.chat + +import com.projectswg.holocore.ProjectSWG + +enum class AdminChatRooms(val roomTitle: String, val roomPath: String) { + SYSTEM_LOG("system log", "SWG." + ProjectSWG.getGalaxy().name + ".admin.SystemLog"), + SPAWNER_LOG("spawner log", "SWG." + ProjectSWG.getGalaxy().name + ".admin.SpawnerLog") +} diff --git a/src/main/java/com/projectswg/holocore/resources/support/global/chat/ChatRoomHandler.java b/src/main/java/com/projectswg/holocore/resources/support/global/chat/ChatRoomHandler.java index a0be428f4..ef3770e05 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/global/chat/ChatRoomHandler.java +++ b/src/main/java/com/projectswg/holocore/resources/support/global/chat/ChatRoomHandler.java @@ -303,7 +303,9 @@ public class ChatRoomHandler { } private void createAdminChannels(ChatAvatar systemAvatar, String basePath) { - createRoom(systemAvatar, false, false, ChatRoomService.LOG_ROOM_PATH, "server log", false); + for (AdminChatRooms room : AdminChatRooms.values()) { + createRoom(systemAvatar, false, false, room.getRoomPath(), room.getRoomTitle(), false); + } } public ChatRoom getRoomById(int roomId) { diff --git a/src/main/java/com/projectswg/holocore/services/support/global/GlobalManager.java b/src/main/java/com/projectswg/holocore/services/support/global/GlobalManager.java index 406d28979..f3445b7c2 100644 --- a/src/main/java/com/projectswg/holocore/services/support/global/GlobalManager.java +++ b/src/main/java/com/projectswg/holocore/services/support/global/GlobalManager.java @@ -1,5 +1,6 @@ package com.projectswg.holocore.services.support.global; +import com.projectswg.holocore.services.support.global.admin.AdministrationManager; import com.projectswg.holocore.services.support.global.chat.ChatManager; import com.projectswg.holocore.services.support.global.commands.CommandManager; import com.projectswg.holocore.services.support.global.health.ServerHealthService; @@ -9,6 +10,8 @@ import me.joshlarson.jlcommon.control.Manager; import me.joshlarson.jlcommon.control.ManagerStructure; @ManagerStructure(children = { + AdministrationManager.class, + ChatManager.class, CommandManager.class, diff --git a/src/main/java/com/projectswg/holocore/services/support/global/admin/AdminSpawnerService.kt b/src/main/java/com/projectswg/holocore/services/support/global/admin/AdminSpawnerService.kt new file mode 100644 index 000000000..0216f79fd --- /dev/null +++ b/src/main/java/com/projectswg/holocore/services/support/global/admin/AdminSpawnerService.kt @@ -0,0 +1,100 @@ +/*********************************************************************************** + * Copyright (c) 2020 /// Project SWG /// www.projectswg.com * + * * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * + * Our goal is to create an emulator which will provide a server for players to * + * continue playing a game similar to the one they used to play. We are basing * + * it on the final publish of the game prior to end-game events. * + * * + * This file is part of Holocore. * + * * + * --------------------------------------------------------------------------------* + * * + * Holocore is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * Holocore is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with Holocore. If not, see . * + ***********************************************************************************/ + +package com.projectswg.holocore.services.support.global.admin + +import com.projectswg.common.data.CRC +import com.projectswg.holocore.intents.support.global.chat.SystemChatRoomMessageIntent +import com.projectswg.holocore.intents.support.global.command.ExecuteCommandIntent +import com.projectswg.holocore.intents.support.objects.swg.ObjectCreatedIntent +import com.projectswg.holocore.resources.support.global.chat.AdminChatRooms +import com.projectswg.holocore.resources.support.npc.spawn.SpawnerType +import com.projectswg.holocore.resources.support.objects.ObjectCreator +import com.projectswg.holocore.resources.support.objects.swg.cell.CellObject +import me.joshlarson.jlcommon.control.IntentHandler +import me.joshlarson.jlcommon.control.Service +import java.io.File +import java.util.* +import java.util.concurrent.locks.ReentrantLock +import kotlin.concurrent.withLock + +class AdminSpawnerService : Service() { + + private val outputFile = File("log/spawners.txt") + private val outputStreamLock = ReentrantLock() + + override fun start(): Boolean { + outputFile.delete() + outputFile.createNewFile() + return true + } + + @IntentHandler + private fun handleChatCommandIntent(eci: ExecuteCommandIntent) { + if (eci.command.crc == COMMAND_CREATE_SPAWNING_ELEMENT) { + val creature = eci.source + val location = creature.location + val building = creature.superParent?.buildoutTag ?: location.terrain.name.toLowerCase(Locale.US).substring(0, 3) + "_world" + val cell = (creature.parent as? CellObject?)?.number ?: 0 + val args = eci.arguments.split(' ', limit = 2) + val type = sanitizeSpawnerType(args.getOrElse(0) { "AREA" }.toUpperCase(Locale.US)) + val comment = args.getOrElse(1) { "NPC" } + val actualYaw = location.yaw + val soeYaw = if (actualYaw < 180) actualYaw else actualYaw - 360 + val output = String.format("%s\t%s\t%s\t%d\t%.1f\t%.1f\t%.1f\t%.0f\t%s%s", location.terrain, building, type, cell, location.x, location.y, location.z, soeYaw, comment, System.lineSeparator()) + outputStreamLock.withLock { + outputFile.appendText(output) + } + val color = when(type) { + "PATROL" -> "#000000" + "WAYPOINT" -> "#0000FF" + else -> "#FFFF00" + } + val egg = ObjectCreator.createObjectFromTemplate(when(type) { + "PATROL" -> SpawnerType.PATROL.objectTemplate + "WAYPOINT" -> "object/tangible/ground_spawning/patrol_waypoint.iff" + else -> SpawnerType.AREA.objectTemplate + }) + egg.moveToContainer(creature.parent, location) + ObjectCreatedIntent.broadcast(egg) + SystemChatRoomMessageIntent.broadcast(AdminChatRooms.SPAWNER_LOG, "${color}The spawner $type ($comment) has been created at your location") + } + } + + companion object { + + private val COMMAND_CREATE_SPAWNING_ELEMENT = CRC.getCrc("createspawningelement") + + private fun sanitizeSpawnerType(type: String): String { + if (type == "AREA" || type == "PATROL" || type == "WAYPOINT") + return type + return "AREA" + } + + } + +} diff --git a/src/main/java/com/projectswg/holocore/services/support/global/admin/AdministrationManager.kt b/src/main/java/com/projectswg/holocore/services/support/global/admin/AdministrationManager.kt new file mode 100644 index 000000000..b3f1409ff --- /dev/null +++ b/src/main/java/com/projectswg/holocore/services/support/global/admin/AdministrationManager.kt @@ -0,0 +1,34 @@ +/*********************************************************************************** + * Copyright (c) 2020 /// Project SWG /// www.projectswg.com * + * * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * + * Our goal is to create an emulator which will provide a server for players to * + * continue playing a game similar to the one they used to play. We are basing * + * it on the final publish of the game prior to end-game events. * + * * + * This file is part of Holocore. * + * * + * --------------------------------------------------------------------------------* + * * + * Holocore is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * Holocore is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with Holocore. If not, see . * + ***********************************************************************************/ + +package com.projectswg.holocore.services.support.global.admin + +import me.joshlarson.jlcommon.control.Manager +import me.joshlarson.jlcommon.control.ManagerStructure + +@ManagerStructure(children = [AdminSpawnerService::class]) +class AdministrationManager : Manager() diff --git a/src/main/java/com/projectswg/holocore/services/support/global/chat/ChatRoomService.java b/src/main/java/com/projectswg/holocore/services/support/global/chat/ChatRoomService.java index 7c216af46..908e4e7af 100644 --- a/src/main/java/com/projectswg/holocore/services/support/global/chat/ChatRoomService.java +++ b/src/main/java/com/projectswg/holocore/services/support/global/chat/ChatRoomService.java @@ -67,7 +67,7 @@ public class ChatRoomService extends Service { @Override public boolean start() { - Log.addWrapper(new ChatRoomLogWrapper(ChatRoomService.LOG_ROOM_PATH)); + Log.addWrapper(new ChatRoomLogWrapper()); return super.start(); } @@ -168,7 +168,7 @@ public class ChatRoomService extends Service { @IntentHandler private void handleSystemChatRoomMessageIntent(SystemChatRoomMessageIntent intent) { - chatRoomHandler.sendMessageToRoomFromSystem(intent.getRoomPath(), intent.getMessage(), new OutOfBandPackage()); + chatRoomHandler.sendMessageToRoomFromSystem(intent.getRoomPath().getRoomPath(), intent.getMessage(), new OutOfBandPackage()); } /* Chat Rooms */ diff --git a/src/main/java/com/projectswg/holocore/utilities/ChatRoomLogWrapper.kt b/src/main/java/com/projectswg/holocore/utilities/ChatRoomLogWrapper.kt index 14fa0531d..8b50e1ce0 100644 --- a/src/main/java/com/projectswg/holocore/utilities/ChatRoomLogWrapper.kt +++ b/src/main/java/com/projectswg/holocore/utilities/ChatRoomLogWrapper.kt @@ -27,11 +27,12 @@ package com.projectswg.holocore.utilities import com.projectswg.holocore.intents.support.global.chat.SystemChatRoomMessageIntent +import com.projectswg.holocore.resources.support.global.chat.AdminChatRooms import me.joshlarson.jlcommon.control.IntentChain import me.joshlarson.jlcommon.log.Log import me.joshlarson.jlcommon.log.LogWrapper -class ChatRoomLogWrapper(private val roomPath: String) : LogWrapper { +class ChatRoomLogWrapper : LogWrapper { private val intentChain = IntentChain() @@ -44,7 +45,7 @@ class ChatRoomLogWrapper(private val roomPath: String) : LogWrapper { Log.LogLevel.ERROR -> " \\#FF0000\\E: "+str.substringAfter(": ") Log.LogLevel.ASSERT -> " \\#FF00FF\\A: "+str.substringAfter(": ") } - intentChain.broadcastAfter(SystemChatRoomMessageIntent(roomPath, message)) + intentChain.broadcastAfter(SystemChatRoomMessageIntent(AdminChatRooms.SYSTEM_LOG, message)) } }