Skip to content

Commit

Permalink
#20 4
Browse files Browse the repository at this point in the history
  • Loading branch information
2nPlusOne committed Jan 4, 2023
1 parent 620f2f0 commit d9f4350
Show file tree
Hide file tree
Showing 7 changed files with 2,353 additions and 11 deletions.
7 changes: 6 additions & 1 deletion backend/classes/user.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
class User {
constructor(user_id, username, socket) {
constructor(user_id, username, socket, auth_token) {
this.user_id = user_id;
this.socket = socket;
this.characters = [];
this.current_character = null;
this.username = username;
this.auth_token = auth_token;
}

checkAuthToken(auth_token) {
return auth_token === this.auth_token;
}

setUsername(username) {
Expand Down
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ app.get('/', function(req, res) {
app.get('/man', function(req, res) {
res.render("man.ejs");
});
app.get('/auth', function(req, res) {
res.render("auth.ejs");
});
app.use(express.static(__dirname + '/public'));

// START SERVER
Expand All @@ -41,7 +44,6 @@ const server = app.listen(PORT, function () {
var users = {};
var chat = [];


// Socket Setup
const io = socket(server);

Expand All @@ -64,9 +66,18 @@ io.on("connection", function (socket) {
console.log("--> Removing Session.");
});

socket.on("on_check_auth", function(data, callback) {
console.log(data);
callback('err', 'msg');
socket.on("on_check_auth", function(cached_auth, callback) {
console.log(cached_auth);
var result = false;
var err = null;

for (let [_, value] of Object.entries(users)) {
if (value.checkAuthToken(cached_auth)) {
result = true;
}
}

callback(err, result);
});

socket.on("on_login", function(user_id) {
Expand All @@ -78,7 +89,8 @@ io.on("connection", function (socket) {
user = new _user_.User( // create the user object
user_id = user_id,
username = "user_" + (Object.keys(users).length + 1), // TODO: replace with user-defined username (with validation)
socket = socket
socket = socket,
auth_token = "hello"
);
users[user_id] = user;
/* When Character is created
Expand Down
Loading

0 comments on commit d9f4350

Please sign in to comment.