-
Notifications
You must be signed in to change notification settings - Fork 11
/
RelayServer.js
122 lines (105 loc) · 3.49 KB
/
RelayServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Developed by: Amin.MasterkinG (https://masterking32.com)
// Github: https://github.com/masterking32/WoW-Server-Relay
// Year: 2024
import Logger from "@ptkdev/logger";
import Net from "net";
import AuthSession from "./AuthSession.js";
import RealmSession from "./RealmSession.js";
class RelayServer {
constructor(config) {
const options = {
language: "en",
colors: true,
debug: config.log_level === "debug",
info: config.log_level === "info" || config.log_level === "debug",
warning:
config.log_level === "warning" ||
config.log_level === "info" ||
config.log_level === "debug",
error:
config.log_level === "error" ||
config.log_level === "warning" ||
config.log_level === "info" ||
config.log_level === "debug",
sponsor: false,
write: false,
type: "log",
};
this.logger = new Logger(options);
this.config = config;
if (this.config.secret_key.length > 64) {
this.logger.error(
"Unable to start the server. The secret key length is too long. The maximum length is 64 characters."
);
process.exit(1);
}
if (this.config.send_relay_packet && this.config.secret_key.length < 1) {
this.logger.error(
"Unable to start the server. The secret key is required when send_relay_packet is enabled. Please set the secret key in the config file."
);
this.logger.error(
"Please note: The secret key should be the same as the main server's secret key, and the recommended length is between 32 and 64 characters."
);
process.exit(1);
}
if (this.config.send_relay_packet && this.config.secret_key === "secret") {
this.logger.error(
"The secret key is set to the default value. Please change the secret key in the config file."
);
this.logger.error(
"Please note: The secret key should be the same as the main server's secret key, and the recommended length is between 32 and 64 characters."
);
process.exit(1);
}
this.auth_server = Net.createServer((socket) => {
this.logger.info(
`New connection from ${socket.remoteAddress} to auth server`
);
let session = new AuthSession(config, socket, this.logger);
session.run();
});
this.realms = {};
for (let realm of config.realms) {
this.realms[realm.realm_id] = Net.createServer((socket) => {
const remoteAddress = socket.remoteAddress;
this.logger.info(
`New connection from ${
remoteAddress && remoteAddress.includes("::ffff:")
? remoteAddress.replace("::ffff:", "")
: remoteAddress
} to realm "${realm.realm_name}"`
);
let session = new RealmSession(
realm.realm_id,
realm,
config,
socket,
this.logger
);
session.run();
});
}
}
run() {
this.auth_server.listen(this.config.auth_port, () => {
this.logger.info(
`Auth server listening on port ${this.config.auth_port}`
);
});
for (let realm of this.config.realms) {
this.realms[realm.realm_id].listen(realm.realm_port, () => {
this.logger.info(
`Realm server listening on port ${realm.realm_port} - ${realm.realm_name}`
);
});
}
}
stop() {
this.auth_server.close();
for (let realm of this.realms) {
realm.close();
}
this.logger.info("Server stopped");
}
}
export default RelayServer;