mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-01-15 23:05:45 -05:00
Added mariadb compatibility for user database
This commit is contained in:
@@ -5,13 +5,12 @@ plugins {
|
||||
id 'java'
|
||||
id 'idea'
|
||||
id "com.github.johnrengelman.shadow" version "5.1.0"
|
||||
id "org.javamodularity.moduleplugin" version "1.5.0"
|
||||
id "org.javamodularity.moduleplugin" version "1.6.0"
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
|
||||
id "org.beryx.jlink" version "2.15.1"
|
||||
id "org.beryx.jlink" version "2.16.2"
|
||||
}
|
||||
|
||||
mainClassName = 'com.projectswg.holocore.ProjectSWG'
|
||||
sourceCompatibility = 12
|
||||
mainClassName = 'holocore/com.projectswg.holocore.ProjectSWG'
|
||||
|
||||
sourceSets {
|
||||
main
|
||||
@@ -61,6 +60,7 @@ dependencies {
|
||||
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.3.50'
|
||||
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.0'
|
||||
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
|
||||
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.5.2'
|
||||
compile group: 'org.mongodb', name: 'mongodb-driver-sync', version: '3.11.0'
|
||||
compile group: 'me.joshlarson', name: "fast-json", version: '3.0.0'
|
||||
compile group: 'me.joshlarson', name: 'jlcommon-network', version: '1.0.0'
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.database
|
||||
|
||||
import com.mongodb.client.MongoDatabase
|
||||
import com.mongodb.client.model.Filters
|
||||
import me.joshlarson.jlcommon.log.Log
|
||||
import java.sql.DriverManager
|
||||
import java.util.logging.Handler
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.LogRecord
|
||||
import java.util.logging.Logger
|
||||
|
||||
class Database(mongo: MongoDatabase) {
|
||||
|
||||
val config = DatabaseTable(mongo.getCollection("config"), null, null, null)
|
||||
private val configuration = config.mongo.find(Filters.exists("connector")).map { DatabaseConfiguration(it) }.first()
|
||||
private val connection = if (configuration == null || configuration.connector != "mariadb") null
|
||||
else DriverManager.getConnection("jdbc:mariadb://${configuration.host}:${configuration.port}/${configuration.database}?autoReconnect=true&user=${configuration.user}&password=${configuration.pass}")
|
||||
val users = DatabaseTable(mongo.getCollection("users"), configuration, connection, configuration?.tables?.get("users"))
|
||||
val objects = DatabaseTable(mongo.getCollection("objects"), configuration, connection, configuration?.tables?.get("objects"))
|
||||
val resources = DatabaseTable(mongo.getCollection("resources"), configuration, connection, configuration?.tables?.get("resources"))
|
||||
|
||||
init {
|
||||
setupMongoLogging()
|
||||
}
|
||||
|
||||
private fun setupMongoLogging() {
|
||||
var mongoLogger: Logger? = Logger.getLogger("com.mongodb")
|
||||
while (mongoLogger != null) {
|
||||
for (handler in mongoLogger.handlers) {
|
||||
mongoLogger.removeHandler(handler)
|
||||
}
|
||||
if (mongoLogger.parent != null)
|
||||
mongoLogger = mongoLogger.parent
|
||||
else
|
||||
break
|
||||
}
|
||||
mongoLogger?.addHandler(object : Handler() {
|
||||
override fun publish(record: LogRecord) {
|
||||
when (record.level) {
|
||||
Level.INFO -> Log.i("MongoDB: %s", record.message)
|
||||
Level.WARNING -> Log.w("MongoDB: %s", record.message)
|
||||
Level.SEVERE -> Log.e("MongoDB: %s", record.message)
|
||||
else -> Log.t("MongoDB: %s", record.message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun flush() {}
|
||||
override fun close() {}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.database
|
||||
|
||||
import org.bson.Document
|
||||
|
||||
|
||||
class DatabaseConfiguration(doc: Document) {
|
||||
|
||||
val connector: String = doc.getString("connector") ?: "mongodb"
|
||||
val host: String = doc.getString("host") ?: ""
|
||||
val port: Int = doc.getInteger("port", 0)
|
||||
val database: String = doc.getString("database") ?: ""
|
||||
val user: String = doc.getString("user") ?: ""
|
||||
val pass: String = doc.getString("pass") ?: ""
|
||||
val accessLevels = doc.getList("accessLevels", Document::class.java, ArrayList())
|
||||
.map { ConfigurationAccessLevels(it) }
|
||||
.filter { it.user.isNotEmpty() }
|
||||
.groupBy { it.user }
|
||||
.mapValues { it.value.last().accessLevel }
|
||||
val tables: Map<String, String> = doc.get("tables", Document()).toMap().filter { it.key is String && it.value is String }.mapValues { it.value as String }
|
||||
|
||||
class ConfigurationAccessLevels(doc: Document) {
|
||||
val user: String = doc.getString("user") ?: ""
|
||||
val accessLevel: String = doc.getString("accessLevel") ?: "player"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +1,38 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.mongodb
|
||||
package com.projectswg.holocore.resources.support.data.server_info.database
|
||||
|
||||
import com.mongodb.client.MongoCollection
|
||||
import com.mongodb.client.model.Filters
|
||||
import com.mongodb.client.model.IndexOptions
|
||||
import com.mongodb.client.model.Indexes
|
||||
import org.bson.Document
|
||||
import java.sql.Connection
|
||||
|
||||
class PswgUserDatabase(private val collection: MongoCollection<Document>?) {
|
||||
class DatabaseTable(val mongo: MongoCollection<Document>, val configuration: DatabaseConfiguration?, val mariaConnection: Connection?, val mariaTable: String?) {
|
||||
|
||||
init {
|
||||
collection?.createIndex(Indexes.ascending("username"), IndexOptions().unique(true))
|
||||
}
|
||||
|
||||
fun getUser(username: String): UserMetadata? {
|
||||
return collection
|
||||
?.find(Filters.eq("username", username))
|
||||
?.map { UserMetadata(it) }
|
||||
?.first()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UserMetadata(doc: Document) {
|
||||
|
||||
val accountId: String = doc.getObjectId("_id").toHexString()
|
||||
val username: String = doc.getString("username")
|
||||
val password: String = doc.getString("password")
|
||||
val accessLevel: String = doc.getString("accessLevel")
|
||||
val isBanned: Boolean = doc.getBoolean("banned")
|
||||
|
||||
override fun toString(): String = "UserMetadata[username=$username accessLevel=$accessLevel banned=$isBanned]"
|
||||
override fun equals(other: Any?): Boolean = if (other is UserMetadata) accountId == other.accountId else false
|
||||
override fun hashCode(): Int = accountId.hashCode()
|
||||
fun isMariaDefined() = mariaConnection != null && mariaTable != null
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.database
|
||||
|
||||
/**
|
||||
* Empty config database that only returns the defaults
|
||||
*/
|
||||
interface PswgConfigDatabase {
|
||||
|
||||
fun getString(o: Any, key: String, def: String): String
|
||||
fun getBoolean(o: Any, key: String, def: Boolean): Boolean
|
||||
fun getInt(o: Any, key: String, def: Int): Int
|
||||
fun getDouble(o: Any, key: String, def: Double): Double
|
||||
fun getLong(o: Any, key: String, def: Long): Long
|
||||
|
||||
companion object {
|
||||
|
||||
fun createDefault(): PswgConfigDatabase {
|
||||
return object : PswgConfigDatabase {
|
||||
override fun getString(o: Any, key: String, def: String): String = def
|
||||
override fun getBoolean(o: Any, key: String, def: Boolean): Boolean = def
|
||||
override fun getInt(o: Any, key: String, def: Int): Int = def
|
||||
override fun getDouble(o: Any, key: String, def: Double): Double = def
|
||||
override fun getLong(o: Any, key: String, def: Long): Long = def
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.database
|
||||
|
||||
import com.projectswg.common.data.encodables.mongo.MongoData
|
||||
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
|
||||
|
||||
interface PswgObjectDatabase {
|
||||
|
||||
val objects: List<MongoData>
|
||||
|
||||
fun addObject(obj: SWGObject)
|
||||
fun addObjects(objects: Collection<SWGObject>)
|
||||
|
||||
fun removeObject(id: Long): Boolean
|
||||
|
||||
fun getCharacterCount(account: String): Int
|
||||
fun isCharacter(firstName: String): Boolean
|
||||
|
||||
fun clearObjects(): Long
|
||||
|
||||
companion object {
|
||||
|
||||
fun createDefault(): PswgObjectDatabase {
|
||||
return object : PswgObjectDatabase {
|
||||
override val objects: List<MongoData> = ArrayList()
|
||||
override fun addObject(obj: SWGObject) {}
|
||||
override fun addObjects(objects: Collection<SWGObject>) {}
|
||||
override fun removeObject(id: Long): Boolean = true
|
||||
override fun getCharacterCount(account: String): Int = 0
|
||||
override fun isCharacter(firstName: String): Boolean = false
|
||||
override fun clearObjects(): Long = 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.database
|
||||
|
||||
import com.projectswg.holocore.resources.gameplay.crafting.resource.galactic.GalacticResource
|
||||
|
||||
interface PswgResourceDatabase {
|
||||
|
||||
var resources: List<GalacticResource>
|
||||
|
||||
companion object {
|
||||
|
||||
fun createDefault(): PswgResourceDatabase {
|
||||
return object : PswgResourceDatabase {
|
||||
override var resources: List<GalacticResource> = ArrayList()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.database
|
||||
|
||||
import com.projectswg.holocore.resources.support.global.player.AccessLevel
|
||||
|
||||
interface PswgUserDatabase {
|
||||
|
||||
fun getUser(username: String): UserMetadata?
|
||||
|
||||
companion object {
|
||||
|
||||
fun createDefault(): PswgUserDatabase {
|
||||
return object : PswgUserDatabase {
|
||||
override fun getUser(username: String): UserMetadata? = null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UserMetadata(val accountId: String, val username: String, val password: String, val accessLevel: AccessLevel, val isBanned: Boolean) {
|
||||
|
||||
override fun toString(): String = "UserMetadata[username=$username accessLevel=$accessLevel banned=$isBanned]"
|
||||
override fun equals(other: Any?): Boolean = if (other is UserMetadata) accountId == other.accountId else false
|
||||
override fun hashCode(): Int = accountId.hashCode()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.mariadb
|
||||
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.DatabaseTable
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.PswgUserDatabase
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.UserMetadata
|
||||
import com.projectswg.holocore.resources.support.global.player.AccessLevel
|
||||
import me.joshlarson.jlcommon.log.Log
|
||||
import java.sql.ResultSet
|
||||
import java.sql.SQLException
|
||||
import java.util.*
|
||||
|
||||
class PswgUserDatabaseMaria(private val database: DatabaseTable): PswgUserDatabase {
|
||||
|
||||
private val getUserStatement = ThreadLocal.withInitial { database.mariaConnection!!.prepareStatement("SELECT userID, password, banned FROM ${database.mariaTable!!} WHERE username = $1") }
|
||||
|
||||
override fun getUser(username: String): UserMetadata? {
|
||||
try {
|
||||
val accessLevel = when (database.configuration?.accessLevels?.get(username)) {
|
||||
"warden" -> AccessLevel.WARDEN
|
||||
"csr" -> AccessLevel.CSR
|
||||
"qa" -> AccessLevel.QA
|
||||
"dev" -> AccessLevel.DEV
|
||||
else -> AccessLevel.PLAYER
|
||||
}
|
||||
val statement = getUserStatement.get()
|
||||
statement.setString(1, username)
|
||||
statement.executeQuery().use { set ->
|
||||
return UserMetadata(accountId = set.getInt("userId").toString(16).toUpperCase(Locale.US),
|
||||
username = username,
|
||||
password = set.getString("password") ?: return null,
|
||||
accessLevel = accessLevel,
|
||||
isBanned = set.getInt("banned") != 0)
|
||||
}
|
||||
} catch (e: SQLException) {
|
||||
Log.w("SQLException when looking up user: $username")
|
||||
Log.w(e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private inline fun (ResultSet).use(op: (ResultSet) -> Unit) {
|
||||
@Suppress("ConvertTryFinallyToUseCall")
|
||||
try {
|
||||
op(this)
|
||||
} finally {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.mongodb
|
||||
|
||||
@@ -31,20 +31,16 @@ import com.mongodb.client.MongoCollection
|
||||
import com.mongodb.client.model.Filters
|
||||
import com.mongodb.client.model.IndexOptions
|
||||
import com.mongodb.client.model.Indexes
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.PswgConfigDatabase
|
||||
import org.bson.Document
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Empty config database that only returns the defaults
|
||||
*/
|
||||
class PswgConfigDatabase(private val collection: MongoCollection<Document>?) {
|
||||
class PswgConfigDatabaseMongo(private val collection: MongoCollection<Document>) : PswgConfigDatabase {
|
||||
|
||||
init {
|
||||
collection?.createIndex(Indexes.ascending("package"), IndexOptions().unique(true))
|
||||
collection.createIndex(Indexes.ascending("package"), IndexOptions().unique(true))
|
||||
}
|
||||
|
||||
fun getString(o: Any, key: String, def: String): String {
|
||||
collection ?: return def
|
||||
override fun getString(o: Any, key: String, def: String): String {
|
||||
for (config in getConfigurations(o)) {
|
||||
if (config.containsKey(key))
|
||||
return config.getString(key)
|
||||
@@ -52,8 +48,7 @@ class PswgConfigDatabase(private val collection: MongoCollection<Document>?) {
|
||||
return def
|
||||
}
|
||||
|
||||
fun getBoolean(o: Any, key: String, def: Boolean): Boolean {
|
||||
collection ?: return def
|
||||
override fun getBoolean(o: Any, key: String, def: Boolean): Boolean {
|
||||
for (config in getConfigurations(o)) {
|
||||
if (config.containsKey(key))
|
||||
return config.getBoolean(key)!!
|
||||
@@ -61,8 +56,7 @@ class PswgConfigDatabase(private val collection: MongoCollection<Document>?) {
|
||||
return def
|
||||
}
|
||||
|
||||
fun getInt(o: Any, key: String, def: Int): Int {
|
||||
collection ?: return def
|
||||
override fun getInt(o: Any, key: String, def: Int): Int {
|
||||
for (config in getConfigurations(o)) {
|
||||
if (config.containsKey(key))
|
||||
return config.getInteger(key)!!
|
||||
@@ -70,8 +64,7 @@ class PswgConfigDatabase(private val collection: MongoCollection<Document>?) {
|
||||
return def
|
||||
}
|
||||
|
||||
fun getDouble(o: Any, key: String, def: Double): Double {
|
||||
collection ?: return def
|
||||
override fun getDouble(o: Any, key: String, def: Double): Double {
|
||||
for (config in getConfigurations(o)) {
|
||||
if (config.containsKey(key))
|
||||
return config.getDouble(key)!!
|
||||
@@ -79,8 +72,7 @@ class PswgConfigDatabase(private val collection: MongoCollection<Document>?) {
|
||||
return def
|
||||
}
|
||||
|
||||
fun getLong(o: Any, key: String, def: Long): Long {
|
||||
collection ?: return def
|
||||
override fun getLong(o: Any, key: String, def: Long): Long {
|
||||
for (config in getConfigurations(o)) {
|
||||
if (config.containsKey(key))
|
||||
return config.getLong(key)!!
|
||||
@@ -89,7 +81,6 @@ class PswgConfigDatabase(private val collection: MongoCollection<Document>?) {
|
||||
}
|
||||
|
||||
private fun getConfigurations(o: Any): List<Document> {
|
||||
collection!! // Should be verified in calling functions
|
||||
var packageKey = if (o is Class<*>) o.packageName else o.javaClass.packageName
|
||||
require(packageKey.startsWith("com.projectswg.holocore")) { "packageKey must be a part of holocore, was: $packageKey" }
|
||||
|
||||
@@ -1,75 +1,47 @@
|
||||
package com.projectswg.holocore.resources.support.data.server_info.mongodb
|
||||
|
||||
import com.mongodb.WriteConcern
|
||||
import com.mongodb.client.MongoClients
|
||||
import com.mongodb.client.MongoCollection
|
||||
import com.mongodb.client.MongoDatabase
|
||||
import me.joshlarson.jlcommon.log.Log
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.*
|
||||
import com.projectswg.holocore.resources.support.data.server_info.mariadb.PswgUserDatabaseMaria
|
||||
import org.bson.Document
|
||||
import java.util.logging.Handler
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.LogRecord
|
||||
import java.util.logging.Logger
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object PswgDatabase {
|
||||
|
||||
private val database = ObjectRef<MongoDatabase?>(null)
|
||||
val config by DatabaseDelegate(database, "config") { PswgConfigDatabase(it?.withWriteConcern(WriteConcern.ACKNOWLEDGED)) }
|
||||
val users by DatabaseDelegate(database, "users") { PswgUserDatabase(it?.withWriteConcern(WriteConcern.ACKNOWLEDGED)) }
|
||||
val objects by DatabaseDelegate(database, "objects") { PswgObjectDatabase(it?.withWriteConcern(WriteConcern.JOURNALED)) }
|
||||
val resources by DatabaseDelegate(database, "resources") { PswgResourceDatabase(it?.withWriteConcern(WriteConcern.ACKNOWLEDGED)) }
|
||||
private var configImpl = PswgConfigDatabase.createDefault()
|
||||
private var usersImpl = PswgUserDatabase.createDefault()
|
||||
private var objectsImpl = PswgObjectDatabase.createDefault()
|
||||
private var resourcesImpl = PswgResourceDatabase.createDefault()
|
||||
|
||||
val config: PswgConfigDatabase
|
||||
get() = configImpl
|
||||
val users: PswgUserDatabase
|
||||
get() = usersImpl
|
||||
val objects: PswgObjectDatabase
|
||||
get() = objectsImpl
|
||||
val resources: PswgResourceDatabase
|
||||
get() = resourcesImpl
|
||||
|
||||
fun initialize(connectionString: String, databaseName: String) {
|
||||
setupMongoLogging()
|
||||
val client = MongoClients.create(connectionString)
|
||||
val database = client.getDatabase(databaseName)
|
||||
val databaseConfig = Database(database)
|
||||
|
||||
this.database.element = database
|
||||
val config = PswgConfigDatabaseMongo(databaseConfig.config.mongo)
|
||||
val users = initTable(databaseConfig.users, defaultCreator = {PswgUserDatabase.createDefault()}, mariaInitializer = ::PswgUserDatabaseMaria, mongoInitializer = ::PswgUserDatabaseMongo)
|
||||
val objects = initTable(databaseConfig.objects, defaultCreator = {PswgObjectDatabase.createDefault()}, mongoInitializer = ::PswgObjectDatabaseMongo)
|
||||
val resources = initTable(databaseConfig.resources, defaultCreator = {PswgResourceDatabase.createDefault()}, mongoInitializer = ::PswgResourceDatabaseMongo)
|
||||
|
||||
this.configImpl = config
|
||||
this.usersImpl = users
|
||||
this.objectsImpl = objects
|
||||
this.resourcesImpl = resources
|
||||
}
|
||||
|
||||
private fun setupMongoLogging() {
|
||||
var mongoLogger: Logger? = Logger.getLogger("com.mongodb")
|
||||
while (mongoLogger != null) {
|
||||
for (handler in mongoLogger.handlers) {
|
||||
mongoLogger.removeHandler(handler)
|
||||
}
|
||||
if (mongoLogger.parent != null)
|
||||
mongoLogger = mongoLogger.parent
|
||||
else
|
||||
break
|
||||
}
|
||||
mongoLogger?.addHandler(object : Handler() {
|
||||
override fun publish(record: LogRecord) {
|
||||
when (record.level) {
|
||||
Level.INFO -> Log.i("MongoDB: %s", record.message)
|
||||
Level.WARNING -> Log.w("MongoDB: %s", record.message)
|
||||
Level.SEVERE -> Log.e("MongoDB: %s", record.message)
|
||||
else -> Log.t("MongoDB: %s", record.message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun flush() {}
|
||||
override fun close() {}
|
||||
})
|
||||
private fun <T> initTable(table: DatabaseTable, defaultCreator: () -> T, mariaInitializer: (DatabaseTable) -> T = {defaultCreator()}, mongoInitializer: (MongoCollection<Document>) -> T = {defaultCreator()}): T {
|
||||
if (table.isMariaDefined())
|
||||
return mariaInitializer(table)
|
||||
return mongoInitializer(table.mongo)
|
||||
}
|
||||
|
||||
private class DatabaseDelegate<T>(private val database: ObjectRef<MongoDatabase?>, private val collectionName: String, private var databaseSupplier: (MongoCollection<Document>?) -> T) {
|
||||
|
||||
private var prevDatabase: MongoDatabase? = null
|
||||
private var prevReturn: T = databaseSupplier(null)
|
||||
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
val database = this.database.element
|
||||
if (prevDatabase != database) {
|
||||
this.prevDatabase = database
|
||||
this.prevReturn = databaseSupplier(database?.getCollection(collectionName))
|
||||
}
|
||||
return prevReturn
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ObjectRef<T: Any?>(var element: T)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.mongodb
|
||||
|
||||
@@ -31,28 +31,26 @@ import com.mongodb.client.MongoCollection
|
||||
import com.mongodb.client.model.*
|
||||
import com.projectswg.common.data.encodables.mongo.MongoData
|
||||
import com.projectswg.holocore.resources.support.data.persistable.SWGObjectFactory
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.PswgObjectDatabase
|
||||
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
|
||||
import org.bson.Document
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
import java.util.stream.Collectors.toList
|
||||
|
||||
class PswgObjectDatabase(private val collection: MongoCollection<Document>?) {
|
||||
class PswgObjectDatabaseMongo(private val collection: MongoCollection<Document>) : PswgObjectDatabase {
|
||||
|
||||
val objects: List<MongoData>
|
||||
get() = collection?.find()?.map { MongoData(it) }?.into(ArrayList()) ?: ArrayList()
|
||||
override val objects: List<MongoData>
|
||||
get() = collection.find().map { MongoData(it) }.into(ArrayList()) ?: ArrayList()
|
||||
|
||||
init {
|
||||
collection?.createIndex(Indexes.ascending("id"), IndexOptions().unique(true))
|
||||
collection.createIndex(Indexes.ascending("id"), IndexOptions().unique(true))
|
||||
}
|
||||
|
||||
fun addObject(obj: SWGObject) {
|
||||
collection ?: return
|
||||
override fun addObject(obj: SWGObject) {
|
||||
collection.replaceOne(Filters.eq("id", obj.objectId), SWGObjectFactory.save(obj, MongoData()).toDocument(), ReplaceOptions().upsert(true))
|
||||
}
|
||||
|
||||
fun addObjects(objects: Collection<SWGObject>) {
|
||||
collection ?: return
|
||||
override fun addObjects(objects: Collection<SWGObject>) {
|
||||
if (objects.isEmpty())
|
||||
return
|
||||
collection.bulkWrite(objects.stream()
|
||||
@@ -67,26 +65,22 @@ class PswgObjectDatabase(private val collection: MongoCollection<Document>?) {
|
||||
BulkWriteOptions().ordered(false))
|
||||
}
|
||||
|
||||
fun removeObject(id: Long): Boolean {
|
||||
collection ?: return true
|
||||
override fun removeObject(id: Long): Boolean {
|
||||
return collection.deleteOne(Filters.eq("id", id)).deletedCount > 0
|
||||
}
|
||||
|
||||
fun getCharacterCount(account: String): Int {
|
||||
collection ?: return 0
|
||||
override fun getCharacterCount(account: String): Int {
|
||||
return collection.countDocuments(Filters.eq("account", account)).toInt()
|
||||
}
|
||||
|
||||
fun isCharacter(firstName: String): Boolean {
|
||||
collection ?: return false
|
||||
override fun isCharacter(firstName: String): Boolean {
|
||||
return collection.countDocuments(Filters.and(
|
||||
Filters.regex("template", "object/creature/player/shared_.+\\.iff"),
|
||||
Filters.regex("base3.objectName", Pattern.compile(Pattern.quote(firstName) + "( .+|$)", Pattern.CASE_INSENSITIVE))
|
||||
)) > 0
|
||||
}
|
||||
|
||||
fun clearObjects(): Long {
|
||||
collection ?: return 0
|
||||
override fun clearObjects(): Long {
|
||||
return collection.deleteMany(Filters.exists("_id")).deletedCount
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http:></http:>//www.gnu.org/licenses/>. *
|
||||
*/
|
||||
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.mongodb
|
||||
|
||||
@@ -31,16 +31,16 @@ import com.mongodb.client.MongoCollection
|
||||
import com.mongodb.client.model.*
|
||||
import com.projectswg.common.data.encodables.mongo.MongoData
|
||||
import com.projectswg.holocore.resources.gameplay.crafting.resource.galactic.GalacticResource
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.PswgResourceDatabase
|
||||
import org.bson.Document
|
||||
import java.util.*
|
||||
import java.util.stream.Collectors.toList
|
||||
|
||||
class PswgResourceDatabase(private val collection: MongoCollection<Document>?) {
|
||||
class PswgResourceDatabaseMongo(private val collection: MongoCollection<Document>) : PswgResourceDatabase {
|
||||
|
||||
var resources: List<GalacticResource>
|
||||
get() = collection?.find()?.map { MongoData.create(it) { GalacticResource() } }?.into(ArrayList()) ?: ArrayList()
|
||||
override var resources: List<GalacticResource>
|
||||
get() = collection.find().map { MongoData.create(it) { GalacticResource() } }.into(ArrayList()) ?: ArrayList()
|
||||
set(value) {
|
||||
collection?.bulkWrite(value.stream()
|
||||
collection.bulkWrite(value.stream()
|
||||
.map { resource ->
|
||||
ReplaceOneModel(
|
||||
Filters.eq("id", resource.id), // match the resource id
|
||||
@@ -53,7 +53,7 @@ class PswgResourceDatabase(private val collection: MongoCollection<Document>?) {
|
||||
}
|
||||
|
||||
init {
|
||||
collection?.createIndex(Indexes.ascending("id"), IndexOptions().unique(true))
|
||||
collection.createIndex(Indexes.ascending("id"), IndexOptions().unique(true))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2019 /// 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 <http://www.gnu.org/licenses/>. *
|
||||
***********************************************************************************/
|
||||
|
||||
package com.projectswg.holocore.resources.support.data.server_info.mongodb
|
||||
|
||||
import com.mongodb.client.MongoCollection
|
||||
import com.mongodb.client.model.Filters
|
||||
import com.mongodb.client.model.IndexOptions
|
||||
import com.mongodb.client.model.Indexes
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.PswgUserDatabase
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.UserMetadata
|
||||
import com.projectswg.holocore.resources.support.global.player.AccessLevel
|
||||
import org.bson.Document
|
||||
|
||||
class PswgUserDatabaseMongo(private val mongoCollection: MongoCollection<Document>) : PswgUserDatabase {
|
||||
|
||||
init {
|
||||
mongoCollection.createIndex(Indexes.ascending("username"), IndexOptions().unique(true))
|
||||
}
|
||||
|
||||
override fun getUser(username: String): UserMetadata? {
|
||||
return mongoCollection
|
||||
.find(Filters.eq("username", username))
|
||||
.map { createUserMetadata(it) }
|
||||
.first()
|
||||
}
|
||||
|
||||
private fun createUserMetadata(doc: Document): UserMetadata {
|
||||
val accessLevel = when (doc.getString("accessLevel")) {
|
||||
"warden" -> AccessLevel.WARDEN
|
||||
"csr" -> AccessLevel.CSR
|
||||
"qa" -> AccessLevel.QA
|
||||
"dev" -> AccessLevel.DEV
|
||||
else -> AccessLevel.PLAYER
|
||||
}
|
||||
return UserMetadata(accountId = doc.getObjectId("_id").toHexString(),
|
||||
username = doc.getString("username"),
|
||||
password = doc.getString("password"),
|
||||
accessLevel = accessLevel,
|
||||
isBanned = doc.getBoolean("banned"))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,7 +63,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CreatureObject extends TangibleObject {
|
||||
public class
|
||||
CreatureObject extends TangibleObject {
|
||||
|
||||
private transient long lastReserveOperation = 0;
|
||||
|
||||
|
||||
@@ -48,10 +48,9 @@ import com.projectswg.holocore.intents.support.global.zone.creation.DeleteCharac
|
||||
import com.projectswg.holocore.intents.support.objects.swg.DestroyObjectIntent;
|
||||
import com.projectswg.holocore.intents.support.objects.swg.ObjectCreatedIntent;
|
||||
import com.projectswg.holocore.resources.support.data.server_info.StandardLog;
|
||||
import com.projectswg.holocore.resources.support.data.server_info.database.UserMetadata;
|
||||
import com.projectswg.holocore.resources.support.data.server_info.mongodb.PswgDatabase;
|
||||
import com.projectswg.holocore.resources.support.data.server_info.mongodb.UserMetadata;
|
||||
import com.projectswg.holocore.resources.support.global.network.DisconnectReason;
|
||||
import com.projectswg.holocore.resources.support.global.player.AccessLevel;
|
||||
import com.projectswg.holocore.resources.support.global.player.Player;
|
||||
import com.projectswg.holocore.resources.support.global.player.Player.PlayerServer;
|
||||
import com.projectswg.holocore.resources.support.global.player.PlayerState;
|
||||
@@ -229,14 +228,7 @@ public class LoginService extends Service {
|
||||
}
|
||||
|
||||
private void onSuccessfulLogin(UserMetadata user, Player player) {
|
||||
switch(user.getAccessLevel()) {
|
||||
default:
|
||||
case "player": player.setAccessLevel(AccessLevel.PLAYER); break;
|
||||
case "warden": player.setAccessLevel(AccessLevel.WARDEN); break;
|
||||
case "csr": player.setAccessLevel(AccessLevel.CSR); break;
|
||||
case "qa": player.setAccessLevel(AccessLevel.QA); break;
|
||||
case "dev": player.setAccessLevel(AccessLevel.DEV); break;
|
||||
}
|
||||
player.setAccessLevel(user.getAccessLevel());
|
||||
player.setAccountId(user.getUsername());
|
||||
player.setPlayerState(PlayerState.LOGGED_IN);
|
||||
new LoginEventIntent(player.getNetworkId(), LoginEvent.LOGIN_SUCCESS).broadcast();
|
||||
|
||||
Reference in New Issue
Block a user