xy-server/game/gate/Server.ts

94 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2025-04-23 09:34:08 +08:00
/**
*
*
* state服务器状态12
*/
import ServerConf from "../../conf/ServerConf";
import GameUtil from "../core/GameUtil";
import Http from "../utils/Http";
export default class Server {
sid: number;
net_ip: string;
net_port: number;
http_port: number;
name: string;
player_num: number;
is_reg: boolean;
state: number;
last_ping: number;
constructor() {
this.sid = 0;
this.net_ip = "127.0.0.1";
this.net_port = 8561;
this.http_port = 8911;
this.name = '未知服务器';
this.player_num = 0;
this.is_reg = false;
this.state = GameUtil.serverState.lower;
this.last_ping = 0;
}
// 读配置
readConf(conf: ServerConf) {
this.sid = conf.server_id;
this.name = conf.server_name;
this.net_ip = conf.outer_ip;
this.net_port = conf.socket_port;
this.http_port = conf.http_port;
}
parse(conf: any) {
this.sid = conf.server_id;
this.name = conf.server_name;
this.net_ip = conf.outer_ip;
this.net_port = conf.socket_port;
this.http_port = conf.http_port;
}
registered(pingtime: any) {
this.last_ping = pingtime;
this.is_reg = true;
this.UpdateState();
}
changePlayerNum(playernum: any) {
this.player_num = playernum;
if (this.state != 0) {
if (this.player_num >= 80) {
this.state = GameUtil.serverState.high;
} else {
this.state = GameUtil.serverState.lower;
}
}
}
UpdateState() {
if (this.is_reg == false) {
return this.state;
}
if (this.player_num >= 80) {
this.state = GameUtil.serverState.high;
} else {
this.state = GameUtil.serverState.lower;
}
return this.state;
}
getPlayerNum() {
return this.player_num;
}
send(event: any, data: any, callback: any) {
Http.sendget(this.net_ip, this.http_port, event, data, callback);
}
toObj(): any {
let result = {
serverId: this.sid,
serverName: this.name,
}
return result;
}
}