forwarder-node
Version:
181 lines (146 loc) • 3.64 kB
JavaScript
/*
Simple and Pure JS version of forwarder
*/
// const
Protocol = {
};
HandleRule = {
};
class ForwardServer {
initCommon(dConfig) {
this.m_Config = {};
this.m_Config.desc = dConfig.desc;
this.m_Config.peerLimit = dConfig.peers;
this.m_Config.port = dConfig.port;
this.m_Config.admin = serverConfig.admin;
this.m_Config.encrypt = dConfig.encrypt;
this.m_Config.compress = dConfig.compress;
this.m_Config.base64 = dConfig.base64;
this.m_Config.isClientMode = dConfig.isClient;
this.m_Config.reconnect = dConfig.reconnect;
this.m_Config.reconnectdelay = dConfig.reconnectdelay;
this.m_Config.address = dConfig.address;
this.m_Config.destId = dConfig.destId;
this.m_Config.timeoutMin = dConfig.timeoutMin;
this.m_Config.timeoutMax = dConfig.timeoutMax;
/*
if (dConfig.encrypt) {
this.initCipherKey(dConfig.encryptkey);
}
*/
this.setRule(Protocol.Forward, HandleRule.Forward);
this.setRule(Protocol.BatchForward, HandleRule.BatchForward);
}
initCipherKey() {
}
setId(id) {
this.m_ID = id;
}
getId() {
return this.m_ID;
}
}
class ForwardServer_WS extends ForwardServer {
}
class ForwardServer_ENet extends ForwardServer {
}
class Forwarder {
constructor() {
this.m_Debug = false;
this.m_ServerList = [];
this.m_ServerDict = {};
}
release() {
}
version() {
return 1;
}
setupLogger() {
}
setDebug(b) {
this.m_Debug = b;
}
setLogLevel(lv) {
}
setProtocolRule() {
}
initServers(lstConfig) {
for (let i = 0; i < lstConfig.length; i++) {
this.createServer(lstConfig[i]);
}
}
createServer(dConfig) {
const netType = dConfig.netType;
const id = dConfig.id;
const server = this.createServerByNetType(netType);
server.initCommon(dConfig);
server.setId(id);
this.m_Servers.push(server);
this.m_ServerDict[server.getId()] = server;
return serverId;
}
createServerByNetType(netType) {
if (netType == "ws") {
return new ForwardServer_WS();
}
if (netType == "enet") {
return new ForwardServer_ENet();
}
}
getServer(serverId) {
return this.m_ServerDict[serverId];
}
removeServer(serverId) {
const server = this.m_ServerDict[serverId];
if (!server) {
return;
}
delete this.m_ServerDict[serverId];
const idx = this.m_ServerList.indexOf(server);
if (idx === -1) {
return;
}
this.m_ServerList.splice(idx, 1);
}
disconnect(serverId) {
}
isConnected(serverId) {
}
setServerDesc() {
}
setTimeout() {
}
setPingInterval() {
}
sendText(serverId, clientId, data) {
}
sendBinary(serverId, clientId, data) {
}
/*
broadcastText(serverId, data) {
}
broadcastBinary(serverId, data) {
}
forwardText(serverId, clientId, data, forwardClientId, isBroadcast, isForceRaw) {
}
forwardBinary(serverId, clientId, data, forwardClientId, isBroadcast, isForceRaw) {
}*/
getCurEvent() {
}
getCurProcessserverId() {
}
getCurProcessClientID() {
}
getCurProcessPacket() {
}
getCurHeaderHostID() {
}
getCurHeaderClientID() {
}
getCurHeaderIP() {
}
pollOnce(serverId) {
}
stat() {
}
};