Comments (7)
请问server.js在哪呢
from noname.
你好,我之前就查看了game文件夹,并没有server.js
请问有没有详细的教程?万分感谢!
才发现作者删了server.js,建议提交一个新的issues,或者你看一下老版本的server.js能不能用
(function(){
var WebSocketServer=require('ws').Server;
var wss=new WebSocketServer({port:8080});
var bannedKeys=[];
var bannedIps=[];
var rooms=[{},{},{},{},{},{},{},{}];
var systemEvent={
content:'公告内容',
avatar:'key_yuri',
nickname:'系统管理员',
title:'系统公告',
};
var events=[systemEvent];
var clients={};
var bannedKeyWords=['ghs','直肠','性交','做爱','http','吃奶','*逼','哈巴狗','美眉','癌','屁眼','艹','**','操你','做鸡','奸','姦','华为','*','狗子','屎','同性恋','肖战','鸡巴','精液','粪水','挂月亮中','贱骨头','吃屁'];
var messages={
enter:function(index,nickname,avatar,config,mode){
this.nickname=nickname;
this.avatar=avatar;
var room=rooms[index];
if(!room){
index=0;
room=rooms[0];
}
this.room=room;
delete this.status;
if(room.owner){
if(room.servermode&&!room.owner._onconfig&&config&&mode){
room.owner.sendl('createroom',index,config,mode);
room.owner._onconfig=this;
room.owner.nickname=nickname;
room.owner.avatar=avatar;
}
else if(!room.config){
this.sendl('enterroomfailed');
}
else{
this.owner=room.owner;
this.owner.sendl('onconnection',this.wsid);
}
util.updaterooms();
}
else{
room.owner=this;
this.sendl('createroom',index);
}
},
changeAvatar:function(nickname,avatar){
this.nickname=nickname;
this.avatar=avatar;
util.updateclients();
},
server:function(cfg){
if(cfg){
this.servermode=true;
var room=rooms[cfg[0]];
if(!room||room.owner){
this.sendl('reloadroom',true);
}
else{
room.owner=this;
this.room=room;
this.nickname=cfg[1];
this.avatar=cfg[2];
this.sendl('createroom',cfg[0],{},'auto')
}
}
else{
for(var i=0;i<rooms.length;i++){
if(!rooms[i].owner){
rooms[i].owner=this;
rooms[i].servermode=true;
this.room=rooms[i];
this.servermode=true;
break;
}
}
util.updaterooms();
}
},
key:function(id){
this.onlineKey=id;
clearTimeout(this.keyCheck);
delete this.keyCheck;
if(typeof id!='string'||bannedKeys.indexOf(id)!=-1){
bannedIps.push(this._socket.remoteAddress);
console.log(id, this._socket.remoteAddress);
this.close();
return;
}
},
events:function(cfg,id,type){
if(bannedKeys.indexOf(id)!=-1||typeof id!='string'){
bannedIps.push(this._socket.remoteAddress);
console.log(id, this._socket.remoteAddress);
this.close();
return;
}
var changed=false;
var time=(new Date()).getTime();
if(cfg&&id){
if(typeof cfg=='string'){
for(var i=0;i<events.length;i++){
if(events[i].id==cfg){
if(type=='join'){
if(events[i].members.indexOf(id)==-1){
events[i].members.push(id);
}
changed=true;
}
else if(type=='leave'){
var index=events[i].members.indexOf(id);
if(index!=-1){
events[i].members.splice(index,1);
if(events[i].members.length==0){
events.splice(i--,1);
}
}
changed=true;
}
}
}
}
else if(cfg.hasOwnProperty('utc')&&
cfg.hasOwnProperty('day')&&
cfg.hasOwnProperty('hour')&&
cfg.hasOwnProperty('content')){
if(events.length>=20){
this.sendl('eventsdenied','total');
}
else if(cfg.utc<=time){
this.sendl('eventsdenied','time');
}
else if(util.isBanned(cfg.content)){
this.sendl('eventsdenied','ban');
}
else{
cfg.nickname=cfg.nickname||'无名玩家';
cfg.avatar=cfg.nickname||'caocao';
cfg.creator=id;
cfg.id=util.getid();
cfg.members=[id];
events.splice(0,1);
events.unshift(cfg);
events.unshift(systemEvent);
changed=true;
}
}
}
if(changed){
util.updateevents();
}
},
config:function(config){
var room=this.room;
if(room&&room.owner==this){
if(room.servermode){
room.servermode=false;
if(this._onconfig){
if(clients[this._onconfig.wsid]){
this._onconfig.owner=this;
this.sendl('onconnection',this._onconfig.wsid);
}
delete this._onconfig;
}
}
room.config=config;
}
util.updaterooms();
},
status:function(str){
if(typeof str=='string'){
this.status=str;
}
else{
delete this.status;
}
util.updateclients();
},
send:function(id,message){
if(clients[id]&&clients[id].owner==this){
try{
clients[id].send(message);
}
catch(e){
clients[id].close();
}
}
},
close:function(id){
if(clients[id]&&clients[id].owner==this){
clients[id].close();
}
},
};
var util={
isBanned:function(str){
for(var i of bannedKeyWords){
if(str.indexOf(i)!=-1) return true;
}
return false;
},
sendl:function(){
var args=[];
for(var i=0;i<arguments.length;i++){
args.push(arguments[i]);
}
try{
this.send(JSON.stringify(args));
}
catch(e){
this.close();
}
},
getid:function(){
return (Math.floor(1000000000+9000000000*Math.random())).toString();
},
getroomlist:function(){
var roomlist=[];
for(var i=0;i<rooms.length;i++){
rooms[i]._num=0;
}
for(var i in clients){
if(clients[i].room&&!clients[i].servermode){
clients[i].room._num++;
}
}
for(var i=0;i<rooms.length;i++){
if(rooms[i].servermode){
roomlist[i]='server';
}
else if(rooms[i].owner&&rooms[i].config){
if(rooms[i]._num==0){
rooms[i].owner.sendl('reloadroom');
}
roomlist[i]=[rooms[i].owner.nickname,rooms[i].owner.avatar,
rooms[i].config,rooms[i]._num];
}
else{
roomlist[i]=null;
}
delete rooms[i]._num;
}
return roomlist;
},
getclientlist:function(){
var clientlist=[];
for(var i in clients){
clientlist.push([clients[i].nickname,clients[i].avatar,!clients[i].room,clients[i].status,clients[i].wsid,clients[i].onlineKey]);
}
return clientlist;
},
updaterooms:function(){
var roomlist=util.getroomlist();
var clientlist=util.getclientlist();
for(var i in clients){
if(!clients[i].room){
clients[i].sendl('updaterooms',roomlist,clientlist);
}
}
},
updateclients:function(){
var clientlist=util.getclientlist();
for(var i in clients){
if(!clients[i].room){
clients[i].sendl('updateclients',clientlist);
}
}
},
checkevents:function(){
if(events.length){
var time=(new Date()).getTime();
for(var i=0;i<events.length;i++){
if(events[i].utc<=time){
events.splice(i--,1);
}
}
}
return events;
},
updateevents:function(){
util.checkevents();
for(var i in clients){
if(!clients[i].room){
clients[i].sendl('updateevents',events);
}
}
}
};
wss.on('connection',function(ws){
ws.sendl=util.sendl;
if(bannedIps.indexOf(ws._socket.remoteAddress)!=-1){
ws.sendl('denied','banned');
setTimeout(function(){
ws.close();
},500);
return;
}
ws.keyCheck=setTimeout(function(){
ws.sendl('denied','key');
setTimeout(function(){
ws.close();
},500);
},2000);
ws.wsid=util.getid();
clients[ws.wsid]=ws;
ws.sendl('roomlist',util.getroomlist(),util.checkevents(),util.getclientlist(ws),ws.wsid);
ws.heartbeat=setInterval(function(){
if(ws.beat){
ws.close();
clearInterval(ws.heartbeat);
}
else{
ws.beat=true;
try{
ws.send('heartbeat');
}
catch(e){
ws.close();
}
}
},60000);
ws.on('message',function(message){
if(!clients[this.wsid]) return;
if(message=='heartbeat'){
this.beat=false;
}
else if(this.owner){
this.owner.sendl('onmessage',this.wsid,message);
}
else{
var arr;
try{
arr=JSON.parse(message);
if(!Array.isArray(arr)){
throw('err');
}
}
catch(e){
this.sendl('denied','banned');
return;
}
if(arr.shift()=='server'){
var type=arr.shift();
if(messages[type]){
messages[type].apply(this,arr);
}
}
}
});
ws.on('close',function(){
for(var i=0;i<rooms.length;i++){
if(rooms[i].owner==this){
rooms[i].owner=null;
rooms[i].config=null;
rooms[i].servermode=false;
for(var j in clients){
if(clients[j].room==rooms[i]&&clients[j]!=this){
clients[j].sendl('selfclose');
// clients[j].close();
// delete clients[j];
}
}
}
}
if(clients[this.wsid]){
if(this.owner){
this.owner.sendl('onclose',this.wsid);
}
delete clients[this.wsid];
}
if(this.room) util.updaterooms();
else util.updateclients();
});
});
}());
from noname.
去阿里云之类的地方开一台VPS服务器(或者用自家电脑开端口映射之类的),将node_modules文件夹和game文件夹下的server.js放在同一文件夹内并上传到服务器,打开命令行,运行
node server.js
,然后去游戏里输入这台服务器的IP地址即可
from noname.
去阿里云之类的地方开一台VPS服务器(或者用自家电脑开端口映射之类的),将node_modules文件夹和游戏文件夹下的server.js放在一个文件夹内并上传到服务器,打开命令行,运行
node server.js
,然后去游戏里输入这台服务器的IP地址即可
谢谢,不过现在没用了,没人陪我玩,哎
from noname.
在/game/server.js
from noname.
你好,我之前就查看了game文件夹,并没有server.js
请问有没有详细的教程?万分感谢!
from noname.
感谢,我开issue询问一下作者。
from noname.
Related Issues (20)
- 手杀傅佥缺阵亡语音
- 身分模式10人UI有问题 HOT 1
- 起刘备在AI代选弃牌时会报错 HOT 2
- 转黄忠与【挟天子以令诸侯】互动错误
- 请问游戏更新的完整包在哪里下载呢 HOT 1
- 无名杀无法获取素材更新 HOT 7
- bug:诸神降临扩展开启后的两个武将包无法在自由选将筛选里显示
- Wiki没有做权限控制,随便就可以新建一个wiki
- noname.core.zip 的合理导入方法
- bug: 满宠 御策 需要血量不为满才可发动,实际应随时可发动。
- HelloGitHub 徽章计划 HOT 1
- 关于中流中重置技能上的疑问, 我感觉下面的结算应该是bug. HOT 2
- 国战左慈袁绍技能错误
- bug:托管后卡死 HOT 1
- 国战邓艾屯田不产生田指示物,无法使用
- 2024新标准包的马腾【雄异】结算错误 HOT 1
- 素材更新报错 HOT 7
- OL蒋琬【自若】无法交换两张手牌的顺序
- 黄承彦发动解阵游戏卡死 HOT 6
- setting window.ai HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from noname.