GithubHelp home page GithubHelp logo

Comments (5)

numbcoder avatar numbcoder commented on July 17, 2024

在数据库 创建用户成功后,会根据 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.

chenyl107 avatar chenyl107 commented on July 17, 2024

$.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.

chenyl107 avatar chenyl107 commented on July 17, 2024

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.

numbcoder avatar numbcoder commented on July 17, 2024

用户登录 和注册,不属于游戏逻辑,所以单独提到 web-Server 里。

from lordofpomelo.

chenyl107 avatar chenyl107 commented on July 17, 2024

嗯,懂了,我自己理解错误了

from lordofpomelo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.