Comments (5)
在数据库 创建用户成功后,会根据 id 生成一个 token
, 并讲 token
返回到客户端
https://github.com/NetEase/lordofpomelo/blob/master/web-server/app.js#L91
res.send({code: 200, token: Token.create(user.id, Date.now(), secret), uid: user.id});
客户端接受到 token
后,通过 game-server 的 auth
接口,game-server 再去验证 token
的有效性,确定是哪个用户
https://github.com/NetEase/lordofpomelo/blob/master/web-server/public/js/ui/clientManager.js#L136
from lordofpomelo.
$.post(httpHost + 'register', {name: name, password: pwd}, function(data) {
if (data.code === 501) {
alert('Username already exists锛�);
loading = false;
} else if (data.code === 200) {
authEntry(data.uid, data.token, function() {
loading = false;
});
} else {
alert('Register fail锛�);
loading = false;
}
}
这个是客户端发送的post请求,我想知道服务器端是怎么接受的,好像和pomelo发送的请求不一样
from lordofpomelo.
app.post('/register', function(req, res) {
//console.log('req.params');
var msg = req.body;
if (!msg.name || !msg.password) {
res.send({code: 500});
return;
}
userDao.createUser(msg.name, msg.password, '', function(err, user) {
if (err || !user) {
console.error(err);
if (err && err.code === 1062) {
res.send({code: 501});
} else {
res.send({code: 500});
}
} else {
console.log('A new user was created! --' + msg.name);
res.send({code: 200, token: Token.create(user.id, Date.now(), secret), uid: user.id});
}
});
});
这个应该是注册的时候后台的代码才对啊,怎么会放在web-server里?
from lordofpomelo.
用户登录 和注册,不属于游戏逻辑,所以单独提到 web-Server 里。
from lordofpomelo.
嗯,懂了,我自己理解错误了
from lordofpomelo.
Related Issues (20)
- why call "sprite.movePath" 2 times
- map.js
- dictionary.json
- fightskill.js
- lord保存数据的问题
- web-server `bin/component.sh` HOT 1
- install error HOT 5
- web-server's js library is not compatible with the exist code
- the callback in funtion createMysqlPool of dao-pool.js is not a function??? HOT 6
- it's error when I choose a role player!!!what's the demo??? so much errors,why???why???why???
- 克隆源码安装直接报错-好郁闷
- TypeError: callback is not a function HOT 4
- 官网好多例子都运行不起来了,要炸 HOT 2
- 各种npm引入的包用不了。。 HOT 2
- 不维护demo了吗? HOT 3
- demo不支持windows安装了吗
- 无法启动game-server HOT 1
- master branch code is not running in my ubuntu 18.04 local system.
- master branch code is not running in my ubuntu 18.04 local system. HOT 3
- http://pomelo.netease.com/art/ 关闭了,能把之前的资源放出来么? HOT 4
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 lordofpomelo.