Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - PostgreSQL database and Flyway migration #161

Draft
wants to merge 147 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
f119227
Add Flyway, run db migration in local PostgreSQL db
P0nk Feb 24, 2023
8bb825e
Add Docker compose support for Postgres
P0nk Feb 24, 2023
f6f3c9c
Initiate Postgres connection pool on startup
P0nk Feb 24, 2023
12745c2
Move notes to the Postgres database
P0nk Feb 24, 2023
d018b0f
Add note receiver index
P0nk Feb 27, 2023
55e1f65
Fix server not able to use note sequence
P0nk Feb 27, 2023
b7c7980
Fix note not showing if case mismatch in name
P0nk Feb 28, 2023
adbdb89
Add maker_recipe table and data (formerly "makercreatedata")
P0nk Mar 1, 2023
9819fd5
Add maker_recipe_ingredient table and data (formerly "makerrecipedata")
P0nk Mar 1, 2023
26357a8
Add maker_reagent table and data (formerly "makerreagentdata")
P0nk Mar 1, 2023
5cecb7a
Add maker_random_reward table and data (formerly "makerrewarddata")
P0nk Mar 1, 2023
c0c0a2d
Get maker reagent from PG db, rework processor (no statics)
P0nk Mar 2, 2023
932f9fc
Merge branch 'master' into feat/postgresql-database
P0nk Mar 2, 2023
b329709
Expose containerized databases to host
P0nk Mar 4, 2023
6073b20
Cache MakerRecipe, move stimulant to MakerInfoProvider
P0nk Mar 4, 2023
f2ca67a
Add tests for MakerInfoProvider
P0nk Mar 4, 2023
9d6574d
Cache maker info with Caffeine
P0nk Mar 4, 2023
d2d4b44
Maker disassembly info to MakerInfoProvider
P0nk Mar 4, 2023
1fd0963
Fix maker disassembly fee not being applied
P0nk Mar 4, 2023
0be4856
Get MakerItemCreateEntry from new info provider
P0nk Mar 8, 2023
7a848cf
Add monster_drop table with data
P0nk Mar 8, 2023
a70f4e3
Add DropProvider and dao for monster drops
P0nk Mar 8, 2023
5376855
Add table, data, and provider method for global drops
P0nk Mar 9, 2023
6bf8785
Fix error in monster_drop query
P0nk Mar 15, 2023
703ae30
Move "steal item" logic to DropProvider
P0nk Mar 15, 2023
7ed7b25
Fix race condition when concurrently Stealing
P0nk Mar 15, 2023
a6a7a26
Clean up Steal stuff in MIP
P0nk Mar 15, 2023
eed94ec
Refactor CommandsExecutor - is no longer static singleton
P0nk Mar 15, 2023
fa3481f
Pass CommandContext to commands
P0nk Mar 15, 2023
45e2b93
Remove "multiple same equip drop" feature
P0nk Mar 15, 2023
a95fa2e
Refactor LootInventory & LootManager
P0nk Mar 15, 2023
cc88d38
Monster drops are retrieved from DropProvider (postgres db)
P0nk Mar 16, 2023
02aa4a2
Global monster drops are retrieved from DropProvider (postgres db)
P0nk Mar 16, 2023
5a35b55
Cache continent drops
P0nk Mar 16, 2023
f2f3abd
Move last pieces of monster drops to DropProvider
P0nk Mar 16, 2023
ab0239b
Add shop and shop_item PG tables with data
P0nk Mar 17, 2023
a496c0f
Add ShopDao
P0nk Mar 17, 2023
7315dd8
Remove redundant scripts for Ariant weapon & armor merchants
P0nk Mar 18, 2023
02c1fe4
Remove custom shops
P0nk Mar 18, 2023
290bf78
Notes about difficulties of DI for scripts
P0nk Mar 18, 2023
ec1450c
Rewrite Mo NPC script to be GMS-like
P0nk Mar 29, 2023
705efb4
Remove access to shops from scripts
P0nk Mar 29, 2023
c71ca7f
Inject ShopFactory
P0nk Mar 29, 2023
2139147
Add getShop to DAO, preparing to refactor shop loading
P0nk Mar 29, 2023
fe9dd75
Instantiate shops in ShopFactory
P0nk Mar 29, 2023
39d7595
Get shop as Optional
P0nk Mar 30, 2023
5f0e9a3
Move Shop stuff to own package
P0nk Mar 30, 2023
c3badba
Convert ShopItem to record
P0nk Mar 30, 2023
699da37
Simplify NPC script start
P0nk Mar 31, 2023
785f74e
Fix HelpCommand not working without static CommandsExecutor
P0nk Mar 31, 2023
46f767d
Merge branch 'master' into feat/postgresql-database
P0nk May 29, 2023
855b66c
Merge branch 'master' into feat/postgresql-database
P0nk Jul 25, 2023
84ad5b4
Remove scroll generator (custom feature)
P0nk Jul 25, 2023
e31465a
Add MonsterCard
P0nk Jul 25, 2023
b3ec325
Add monster card table and initial dao
P0nk Jul 25, 2023
f6aa8ce
Rewrite MonsterBook, touch up chr loading
P0nk Jul 25, 2023
05b7ec7
Add ChannelService to handle cc'ing
P0nk Aug 4, 2023
02d4ff5
Fix global drops not dropping
P0nk Aug 4, 2023
e52f646
Fix batch insert monster cards
P0nk Aug 4, 2023
4e39142
Direct almost all chr saving through CharacterSaver
P0nk Aug 4, 2023
e9819fa
Save cooldowns and diseases as part of normal flow
P0nk Aug 4, 2023
2686b2b
Disconnect client by throwing exception in handler
P0nk Aug 6, 2023
449ab01
Remove "vote points" feature
P0nk Aug 6, 2023
810dbcc
Remove "reward points" feature
P0nk Aug 6, 2023
f44083a
Refactor Client#finishLogin
P0nk Aug 6, 2023
48d9aaa
Clean up Client - visibleWorlds & canRequestCharlist
P0nk Aug 6, 2023
5b5888c
Remove unused stuff in Client
P0nk Aug 6, 2023
bbee8d7
Merge chr name + id wrappers into new CharacterIdentity record
P0nk Aug 6, 2023
f6d06ba
Extract "char list" from Client to handler
P0nk Aug 6, 2023
d5682a5
Add client disconnection logic to TransitionService
P0nk Aug 8, 2023
cb31121
Disconnect client with TransitionService
P0nk Aug 10, 2023
cd75e85
Move some autoban logic to new BanService
P0nk Aug 10, 2023
f33df59
Move some Client#forceDisconnect calls to TransitionService
P0nk Aug 11, 2023
392a350
Merge branch 'master' into feat/postgresql-database
P0nk Aug 20, 2023
033d91e
Merge branch 'master' into feat/postgresql-database
P0nk Nov 8, 2023
a7d03cf
Merge branch 'master' into feat/postgresql-database
P0nk Feb 4, 2024
559fe2d
Merge branch 'refs/heads/master' into feat/postgresql-database
P0nk Sep 2, 2024
09a75e8
Merge branch 'refs/heads/master' into feat/postgresql-database
P0nk Sep 3, 2024
7bd5fa3
Merge branch 'refs/heads/master' into feat/postgresql-database
P0nk Sep 13, 2024
719b079
Refactor unnecessary wrapper boolean
P0nk Sep 13, 2024
f41268c
Handle disconnect solely in TransitionService
P0nk Sep 13, 2024
8bce092
Fix broken global drops since merge from master
P0nk Sep 13, 2024
1b6c016
Fix buddy staying online in buddy list if dc in cash shop
P0nk Sep 13, 2024
758347f
Small refactor of disconnectInternal for readability
P0nk Sep 13, 2024
23a8a33
Move transaction handling to CharacterSaver
P0nk Sep 13, 2024
abbec81
Restructure chr saving - gather stats in record
P0nk Sep 14, 2024
08eeeb5
Rename ...Dao -> ...Repository
P0nk Sep 14, 2024
7297cd0
Separate PG from MySQL chr saving
P0nk Sep 14, 2024
4778482
Remove quest point feature
P0nk Sep 14, 2024
f872664
Remove configurable language feature
P0nk Sep 14, 2024
f827e23
Clean up rewardpoints
P0nk Sep 14, 2024
e57d2a9
Create account, chr tables & save chr to Postgres
P0nk Sep 14, 2024
ce5dee3
Reorder migration scripts - move acc+chr creation earlier
P0nk Sep 14, 2024
0c9643f
CharacterSaver integration test with Testcontainers
P0nk Sep 15, 2024
98d76ad
Prepare centralized chr creation
P0nk Sep 16, 2024
00fc3ed
Handle created chr with spec
P0nk Sep 25, 2024
a9967d5
Fix chr loading due to "monster_card" table not found
P0nk Sep 25, 2024
767c440
Route chr creation to dummy CharacterCreator
P0nk Sep 25, 2024
b4e673b
Make some chr stats nullable to ease migration to PG
P0nk Sep 25, 2024
7335914
Simplify sp saving
P0nk Sep 25, 2024
b852333
Save new chr to PG (doesn't work yet because no account)
P0nk Sep 25, 2024
1d5c26e
Remove SHA-512 password migration
P0nk Sep 26, 2024
bf9c02b
Fix failed chr save due to null jail expiration
P0nk Sep 26, 2024
647e67f
Auto-create account in both MySQL and PG
P0nk Sep 26, 2024
c7f835d
Add DatabaseTest to easily test repositories
P0nk Sep 26, 2024
0f2ef34
Save accepted ToS to PG
P0nk Sep 26, 2024
f33d4fb
Save pin to PG
P0nk Sep 27, 2024
2044166
Save pic to PG
P0nk Sep 27, 2024
082e0c0
Save chr slots to PG
P0nk Sep 27, 2024
5abae50
Rework login, get account from PG
P0nk Sep 27, 2024
4392809
Save gender to PG
P0nk Sep 27, 2024
ec39f0f
Avoid additional db query to get login state during login
P0nk Sep 28, 2024
93bbe86
Use LoginState everywhere
P0nk Sep 28, 2024
55c9d4a
Log out through AccountService
P0nk Sep 28, 2024
1be7753
Disable slow tests that don't provide much value
P0nk Sep 28, 2024
5595f57
Log in through AccountService
P0nk Sep 28, 2024
813768e
Remove AddWorld,AddChannel,RemoveWorld,RemoveChannel cmds
P0nk Sep 29, 2024
0a8591a
Merge "serverTransition" and "inTransition" fields
P0nk Sep 29, 2024
0bb14e4
Log in through AccountService on player login
P0nk Sep 29, 2024
da4a467
Set in transition on log in, now able to enter the game
P0nk Sep 29, 2024
a580e44
Rename AccountService methods
P0nk Sep 29, 2024
4e1aa1e
Rename NOT_LOGGED_IN -> LOGGED_OUT
P0nk Sep 29, 2024
902f1a1
Log out in PG on exit game
P0nk Sep 29, 2024
fa666c9
Rename loginattempt
P0nk Sep 29, 2024
5450c29
Reduce login state updates, fix multi-login on same acc
P0nk Sep 29, 2024
b456201
LoginState enum
P0nk Sep 29, 2024
d00b4ed
Rename "temp_ban_timestamp" -> "temp_banned_until"
P0nk Sep 29, 2024
50524a7
Show correct ban reason
P0nk Sep 29, 2024
a307afa
Unify ban handling on login
P0nk Sep 29, 2024
1c6245f
birthday represented as LocalDate
P0nk Sep 29, 2024
f142e21
Fix broken test
P0nk Sep 29, 2024
99006c2
Set ban through AccountService
P0nk Sep 29, 2024
c0ee1f8
Encapsulate account creation in AccountService
P0nk Sep 29, 2024
e35060d
Handle ban solely through BanService
P0nk Sep 29, 2024
988d898
Clean up tempBanCalendar
P0nk Sep 29, 2024
167937b
Check banned hwid on login
P0nk Sep 29, 2024
7661cd0
Redo ip bans - reduce amount of db queries on login
P0nk Sep 30, 2024
af02f8b
Redo hwid bans - reduce amount of db queries on login
P0nk Oct 1, 2024
5d81e05
Redo mac bans - reduce amount of db queries on login
P0nk Oct 1, 2024
e38344c
Refactor BanService#ban
P0nk Oct 2, 2024
2b6ef9f
Save client addresses async on chr select
P0nk Oct 3, 2024
40425ac
Ban ip, macs & hwid in PG
P0nk Oct 3, 2024
64f99a2
Unban account & ip
P0nk Oct 3, 2024
e295a24
Unban macs & hwid
P0nk Oct 3, 2024
a4f8086
Log out everyone on startup
P0nk Oct 3, 2024
f2b8ced
Move chr MySQL saving to CharacterSaver
P0nk Oct 5, 2024
e4430a3
Merge branch 'master' into feat/postgresql-database
P0nk Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 8 additions & 10 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ server:
DB_PASS: ""
INIT_CONNECTION_POOL_TIMEOUT: 90 # Seconds

PG_DB_URL: "jdbc:postgresql://localhost:5432/cosmic"
PG_DB_SCHEMA: "cosmic"
PG_DB_ADMIN_USERNAME: "cosmic_admin"
PG_DB_ADMIN_PASSWORD: "redsnailshell"
PG_DB_USERNAME: "cosmic_server"
PG_DB_PASSWORD: "bluesnailshell"
PG_DB_CLEAN: false # !!! WARNING !!! Deletes the entire database - starts from scratch.

#Login Configuration
WORLDS: 1 #Initial number of worlds on the server.
WLDLIST_SIZE: 21 #Max possible worlds on the server.
Expand All @@ -185,7 +193,6 @@ server:
BYPASS_PIN_EXPIRATION: 15 #Enables PIN bypass, which will remain active for that account by that client machine for N minutes. Set 0 to disable.

AUTOMATIC_REGISTER: true #Automatically register players when they login with a nonexistent username.
BCRYPT_MIGRATION: true #Performs a migration from old SHA-1 and SHA-512 password to bcrypt.
COLLECTIVE_CHARSLOT: false #Available character slots are contabilized globally rather than per world server.
DETERRED_MULTICLIENT: false #Enables detection of multi-client and suspicious remote IP on the login system.
#Besides blocking logging in with several client sessions on the same machine, this also blocks suspicious login attempts for players that tries to login on an account using several diferent remote addresses.
Expand Down Expand Up @@ -234,7 +241,6 @@ server:
USE_AUTOBAN: false #Commands the server to detect infractors automatically.
USE_AUTOBAN_LOG: true #Log autoban related messages. Still logs even with USE_AUTOBAN disabled.
USE_EXP_GAIN_LOG: false #Logs characters exp gains; logs world rate & coupon exp, total gained exp, and current exp, level can be calculated from "ExpTable".
USE_AUTOSAVE: true #Enables server autosaving feature (saves characters to DB each 1 hour).
USE_SERVER_AUTOASSIGNER: false #HeavenMS-builtin autoassigner, uses algorithm based on distributing AP accordingly with required secondary stat on equipments.
USE_REFRESH_RANK_MOVE: true
USE_ENFORCE_ADMIN_ACCOUNT: false #Forces accounts having GM characters to be treated as a "GM account" by the client (localhost). Some of the GM account perks is the ability to FLY, but unable to TRADE.
Expand All @@ -246,7 +252,6 @@ server:
USE_ENFORCE_ITEM_SUGGESTION: false #Forces the Owl of Minerva and the Cash Shop to always display the defined item array instead of those featured by the players.
USE_ENFORCE_UNMERCHABLE_CASH: true #Forces players to not sell CASH items via merchants, drops of it disappears.
USE_ENFORCE_UNMERCHABLE_PET: true #Forces players to not sell pets via merchants, drops of it disappears. (since non-named pets gets dirty name and other possible DB-related issues)
USE_ENFORCE_MERCHANT_SAVE: true #Forces automatic DB save on merchant owners, at every item movement on shop.
USE_ENFORCE_MDOOR_POSITION: false #Forces mystic door to be spawned near spawnpoints.
USE_SPAWN_CLEAN_MDOOR: false #Makes mystic doors to be spawned without deploy animation. This clears disconnecting issues that may happen when trying to cancel doors a couple seconds after deployment.
USE_SPAWN_RELEVANT_LOOT: true #Forces to only spawn loots that are collectable by the player or any of their party members.
Expand Down Expand Up @@ -359,20 +364,13 @@ server:
USE_FULL_HOLY_SYMBOL: false #Holy symbol doesn't require EXP sharers to work in full.

#Character Configuration
USE_ADD_SLOTS_BY_LEVEL: false #Slots are added each 20 levels.
USE_ADD_RATES_BY_LEVEL: false #Rates are added each 20 levels.
USE_STACK_COUPON_RATES: false #Multiple coupons effects builds up together.
USE_PERFECT_PITCH: false #For lvl 30 or above, each lvlup grants player 1 perfect pitch.

#Quest Configuration
USE_QUEST_RATE: false #Exp/Meso gained by quests uses fixed server exp/meso rate times quest rate as multiplier, instead of player rates.

#Quest Points Configuration
QUEST_POINT_REPEATABLE_INTERVAL: 25 #Minimum interval between repeatable quest completions for quest points to be awarded.
QUEST_POINT_REQUIREMENT: 0 #Exchange factor between N quest points to +1 fame, set 0 to disable the entire quest point mechanism.
QUEST_POINT_PER_QUEST_COMPLETE: 0 #Each completed quest awards N quest points, set 0 to disable.
QUEST_POINT_PER_EVENT_CLEAR: 0 #Each completed event instance awards N quest points, set 0 to disable.

#Guild Configuration
CREATE_GUILD_MIN_PARTNERS: 6 #Minimum number of members on Guild Headquarters to establish a new guild.
CREATE_GUILD_COST: 1500000
Expand Down
2 changes: 2 additions & 0 deletions database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker-db-data/*
docker-pg-db-data/*
3 changes: 0 additions & 3 deletions database/docker-db-data/.gitignore

This file was deleted.

3 changes: 3 additions & 0 deletions database/postgres-scripts/create-db-and-admin-user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE DATABASE cosmic;
CREATE USER cosmic_admin WITH CREATEROLE ENCRYPTED PASSWORD 'redsnailshell';
GRANT ALL PRIVILEGES ON DATABASE cosmic TO cosmic_admin;
9 changes: 0 additions & 9 deletions database/sql/1-db_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,8 @@ CREATE TABLE IF NOT EXISTS `accounts` (
`tempban` timestamp NOT NULL DEFAULT '2005-05-11 00:00:00',
`greason` tinyint(4) NOT NULL DEFAULT '0',
`tos` tinyint(1) NOT NULL DEFAULT '0',
`sitelogged` text,
`webadmin` int(1) DEFAULT '0',
`nick` varchar(20) DEFAULT NULL,
`mute` int(1) DEFAULT '0',
`email` varchar(45) DEFAULT NULL,
`ip` text,
`rewardpoints` int(11) NOT NULL DEFAULT '0',
`votepoints` int(11) NOT NULL DEFAULT '0',
`hwid` varchar(12) NOT NULL DEFAULT '',
`language` int(1) NOT NULL DEFAULT '2',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `ranking1` (`id`,`banned`),
Expand Down Expand Up @@ -144,7 +136,6 @@ CREATE TABLE IF NOT EXISTS `characters` (
`skincolor` int(11) NOT NULL DEFAULT '0',
`gender` int(11) NOT NULL DEFAULT '0',
`fame` int(11) NOT NULL DEFAULT '0',
`fquest` int(11) NOT NULL DEFAULT '0',
`hair` int(11) NOT NULL DEFAULT '0',
`face` int(11) NOT NULL DEFAULT '0',
`ap` int(11) NOT NULL DEFAULT '0',
Expand Down
14 changes: 13 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
build: .
depends_on:
- db
- pg_db
ports:
# Login server
- "8484:8484"
Expand All @@ -19,7 +20,8 @@ services:
- ./wz:/opt/server/wz
environment:
DB_HOST: "db" ## Remember if this is present it will OVERRIDE the host in the config.yaml, if you put here anything other than db, you'll need to change the config.yaml jdbc string to port 3307, and not port 3306

PG_DB_HOST: "pg_db"

db:
image: mysql:8.4.0
environment:
Expand All @@ -31,3 +33,13 @@ services:
volumes:
- ./database/docker-db-data:/var/lib/mysql
- ./database/sql:/docker-entrypoint-initdb.d

pg_db:
image: postgres:15.0
ports:
- "5433:5432"
environment:
POSTGRES_PASSWORD: postgres
volumes:
- ./database/docker-pg-db-data:/var/lib/postgresql/data
- ./database/postgres-scripts:/docker-entrypoint-initdb.d
45 changes: 45 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<jdbi-version>3.45.1</jdbi-version> <!-- Convenience wrapper around JDBC -->
<junit.version>5.10.2</junit.version> <!-- Unit test -->
<mockito.version>5.11.0</mockito.version> <!-- Unit test -->
<testcontainers.version>1.20.1</testcontainers.version> <!-- Docker test with real temporary database -->
<postgresql.version>42.5.4</postgresql.version> <!-- PostgreSQL JDBC driver -->
<flyway.version>9.15.1</flyway.version> <!-- Database migration -->
<caffeine.version>3.1.4</caffeine.version> <!-- Caching -->
<lombok.version>1.18.34</lombok.version> <!-- Code generation -->
</properties>

<dependencies>
Expand All @@ -82,6 +87,17 @@
<artifactId>jcip-annotations</artifactId>
<version>${jcip-annotations.version}</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>${caffeine.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<!-- Database -->
<dependency>
Expand All @@ -94,11 +110,21 @@
<artifactId>mysql-connector-j</artifactId>
<version>${mysql-connector-j.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-core</artifactId>
<version>${jdbi-version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>


<!-- Networking -->
Expand Down Expand Up @@ -188,6 +214,25 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>


</dependencies>

Expand Down
Loading
Loading