Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit 50f4fd1

Browse files
committed
Refactored code
1 parent 060da2f commit 50f4fd1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1174
-549
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ __debug_bin
2222

2323
# Dependency directories
2424
/public
25-
/keys
26-
25+
/static/keys
26+
/static/hotupdate

CONTRIBUTING.md

-2
This file was deleted.

README.md

+4-95
Original file line numberDiff line numberDiff line change
@@ -3,103 +3,12 @@
33
## Current Features
44

55
- [x] Announcements
6-
- [x] Mail
7-
- [ ] Logging in
6+
- [x] Logging in
7+
- [x] Updates
8+
- [ ] Mail
89
- [ ] Missions
910
- [ ] Registering
10-
- [ ] Updates
1111
- [ ] Gacha
1212
- [ ] Events
1313
- [ ] Items & Rewards
14-
- [ ] Operations / Gameplay
15-
16-
## Startup
17-
18-
### Getting Started
19-
20-
When starting up the server, the client only needs to connect for a couple seconds, where then it is safe to disconnect after the update has been installed. This is because the game uses a system where it only stores the remote config file. If you are running on a public Doctorate server, you will get all the updates a normal user would get, this is because Doctorate actually requests the updates from Official Servers on behalf of you and passes back adjusted data!
21-
22-
```mermaid
23-
sequenceDiagram
24-
Client ->> Proxy: GET [HOST] /remote_config
25-
Proxy ->> Server: GET [FAKEHOST] /remote_config
26-
Server--> Client: Response [FAKEHOST] {"gs":"[FAKEHOST]", "as":"[FAKEHOST]"...
27-
Note right of Server: Client now thinks that<br> the [FAKEHOST] is the<br> real host, and sends all<br> requests to that server.
28-
Client ->> Server: GET [FAKEHOST] /announce/version
29-
Server--> Client: Reponse [FAKEHOST] {"resVersion":"22-04-21-10-53-07-1be683"...
30-
Note right of Server: Server sends a version that<br> is greater than the clients<br> current version, causing<br> an update to be requested,<br> which in return, changes<br> the default host.
31-
Client ->> Server: GET [FAKEHOST] /update
32-
Server--> Client: Response [FAKEHOST] *Update Patch*
33-
Client ->> Server: POST [FAKEHOST] /user/login
34-
```
35-
36-
## Creating a new Router
37-
38-
Doctorate uses a module system to register new API routes. Each router "package" is enclosed inside the router. For example, say the game has a new path called "shop", this would be the folder name and then any routes under it are registered accordingly.
39-
40-
```mermaid
41-
graph TD
42-
A[Router]
43-
A --> |/api/shop| B(package shop)
44-
A --> |/api/announce| C(package announce)
45-
A --> |/api/quest| D(package quest)
46-
```
47-
We can create a new package by simply doing something like the following:
48-
```go
49-
// '/router/test/test.go'
50-
package test
51-
52-
// Import the router package
53-
import (
54-
"github.com/Etwodev/Doctorate/server/router"
55-
)
56-
57-
func NewRouter(status bool) router.Router {
58-
// Automatically creates missing tables and more for us
59-
router.Connector.AutoMigrate(&Test{})
60-
return router.NewRouter(initRoutes(), status)
61-
}
62-
63-
func initRoutes() []router.Route {
64-
return []router.Route{
65-
// path, isExperimental, isActivated, method
66-
router.NewGetRoute("/test/test", true, true, TestPostRoute),
67-
}
68-
}
69-
```
70-
TestPostRoute may look something like this:
71-
```go
72-
// '/router/test/test_routes.go
73-
package test
74-
75-
import (
76-
"net/http"
77-
"github.com/Etwodev/Doctorate/server/httputils"
78-
"github.com/Etwodev/Doctorate/server/router"
79-
)
80-
81-
func TestPostRoute(w http.ResponseWriter, r *http.Request) {
82-
var t Test
83-
// Gets all data relating to the object Test
84-
router.Connector.Find(&t)
85-
httputils.RespondWithJSON(w, http.StatusOK, pre)
86-
}
87-
```
88-
89-
We need to make sure we update our main.go file, though!
90-
This is to make sure the router gets initialised and we don't get an empty router.
91-
```go
92-
// main.go
93-
...
94-
routers := []router.Router{
95-
// We call NewRouter(), where "true" is whether the route is should be activated
96-
test.NewRouter(true),
97-
}
98-
99-
// Initilises all the routers
100-
s.InitRouter(routers...)
101-
// In this case, "true" is whether or not to run the server in experimental mode
102-
var r = s.InitRouters(true)
103-
...
104-
```
105-
14+
- [ ] Operations / Gameplay

main.go

+8-25
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,28 @@
11
package main
22

33
import (
4-
5-
// SYSTEM
6-
"log"
7-
"net/http"
8-
9-
// EXTERNAL
10-
"github.com/joho/godotenv"
114
// INTERNAL
12-
"github.com/Etwodev/Doctorate/mitm"
135
"github.com/Etwodev/Doctorate/server"
146
"github.com/Etwodev/Doctorate/server/router"
157

168
// ROUTERS
9+
"github.com/Etwodev/Doctorate/server/router/account"
10+
"github.com/Etwodev/Doctorate/server/router/app"
1711
"github.com/Etwodev/Doctorate/server/router/assetbundle"
1812
"github.com/Etwodev/Doctorate/server/router/config"
13+
"github.com/Etwodev/Doctorate/server/router/user"
1914
)
2015

2116
func main () {
22-
err := godotenv.Load()
23-
24-
if err != nil {
25-
log.Fatal("Error loading .env file")
26-
}
27-
28-
var c = server.CreateConfig()
29-
var s = server.New(c)
17+
var s = server.New()
3018

3119
routers := []router.Router{
3220
config.NewRouter(true),
3321
assetbundle.NewRouter(true),
22+
account.NewRouter(true),
23+
app.NewRouter(true),
24+
user.NewRouter(true),
3425
}
3526

36-
s.InitRouter(routers...)
37-
38-
go func() {
39-
mitm.TestingMain("1", "tcp", "127.0.0.1", "4000")
40-
}()
41-
42-
var handler = s.InitRouters()
43-
44-
log.Fatal(http.ListenAndServe(c.Doctorate.Port, handler))
27+
s.Start(routers...)
4528
}

mitm/.DS_Store

-6 KB
Binary file not shown.

mitm/mitm.go

-48
This file was deleted.

mitm/payloads/.DS_Store

-6 KB
Binary file not shown.

server/helpers/database.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ func Connect(dsn string) error {
1212
var err error
1313
Engine, err = xorm.NewEngine("mysql", dsn)
1414
if err != nil {
15-
log.Fatal().Msgf("Error connecting to MySQL server: %s", err)
15+
log.Fatal().Err(err).Msg("Startup failed!")
1616
}
17-
log.Debug().Msg("Connected to MySQL")
1817
return nil
1918
}

0 commit comments

Comments
 (0)