fixed regex
This commit is contained in:
0
server/src/game-logic.js
Normal file
0
server/src/game-logic.js
Normal file
@@ -56,8 +56,9 @@ function CountIPs(ip)
|
||||
|
||||
function ValidUsername(username)
|
||||
{
|
||||
// \p{L} includes international letters
|
||||
if (username.match(/[^A-Za-z0-9_-]\p{L}/))
|
||||
// unicode stuffs includes international letters instead
|
||||
// of A-Za-z0-9
|
||||
if (username.match(/[^\u00BF-\u1FFF\u2C00-\uD7FF\w_-]/))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -91,6 +92,11 @@ function GetUserByUsername(username)
|
||||
return false;
|
||||
}
|
||||
|
||||
function GetUserIntent(useruid)
|
||||
{
|
||||
return OnlineUsers[useruid].intent;
|
||||
}
|
||||
|
||||
|
||||
function RegisterUser(username, ip)
|
||||
{
|
||||
@@ -112,7 +118,7 @@ function RegisterUser(username, ip)
|
||||
ip: ip,
|
||||
// REGISTERED, CONNECTED, DISCONNECTED
|
||||
state: 'REGISTERED',
|
||||
// LOBYING, GAME, UNDECIDED
|
||||
// LOBYING, GAMETRANSITION, GAME, UNDECIDED
|
||||
intent: 'UNDECIDED',
|
||||
// Doesn't update if state changes
|
||||
connectionid: 'none',
|
||||
@@ -123,18 +129,22 @@ function RegisterUser(username, ip)
|
||||
return OnlineUsers[uid];
|
||||
}
|
||||
|
||||
function DeRegisterUser(userid)
|
||||
function DeRegisterUser(useruid)
|
||||
{
|
||||
delete OnlineUsers[userid];
|
||||
delete OnlineUsers[useruid];
|
||||
}
|
||||
|
||||
function ChangeUserIntent(useruid, intent)
|
||||
{
|
||||
OnlineUsers[useruid].intent = intent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function UserConnectionExists(userid)
|
||||
function UserConnectionExists(useruid)
|
||||
{
|
||||
if (OnlineUsers[userid].state === 'CONNECTED') return true;
|
||||
if (OnlineUsers[userid].state === 'DISCONNECTED') return false;
|
||||
if (OnlineUsers[userid].state === 'REGISTERED') return false;
|
||||
if (OnlineUsers[useruid].state === 'CONNECTED') return true;
|
||||
if (OnlineUsers[useruid].state === 'DISCONNECTED') return false;
|
||||
if (OnlineUsers[useruid].state === 'REGISTERED') return false;
|
||||
}
|
||||
|
||||
function GetUserbyConnection(connectionid)
|
||||
@@ -181,11 +191,12 @@ module.exports = {
|
||||
GetUserByUID: GetUserByUID,
|
||||
GetSafeUserByUID: GetSafeUserByUID,
|
||||
GetUserByUsername: GetUserByUsername,
|
||||
GetUserIntent: GetUserIntent,
|
||||
|
||||
// Change user state exports
|
||||
RegisterUser: RegisterUser,
|
||||
DeRegisterUser: DeRegisterUser,
|
||||
|
||||
ChangeUserIntent: ChangeUserIntent,
|
||||
|
||||
// User connection validation exports
|
||||
UserConnectionExists: UserConnectionExists,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const Registrar = require('./game-registrar.js');
|
||||
const Lobbies = require('./lobbies');
|
||||
const Lobbies = require('./lobbies.js');
|
||||
const GameLogic = require('./game-logic.js')
|
||||
|
||||
/**
|
||||
* This is just to manage the "game" module
|
||||
@@ -9,5 +10,6 @@ const Lobbies = require('./lobbies');
|
||||
|
||||
module.exports = {
|
||||
Registrar: Registrar,
|
||||
Lobbies: Lobbies
|
||||
Lobbies: Lobbies,
|
||||
Game: GameLogic
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ function init()
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
init: init
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function Router(socket)
|
||||
{
|
||||
@@ -47,6 +52,7 @@ async function Router(socket)
|
||||
|
||||
|
||||
socket.on('identify', args => ClientIdentify(socket, args));
|
||||
socket.on('identify-update-intent', args => UpdateIntent(socket, args));
|
||||
|
||||
socket.on('lobby-create', args => LobbyCreate(socket, args));
|
||||
socket.on('lobby-join', args => LobbyJoin(socket, args));
|
||||
@@ -104,6 +110,12 @@ function ClientIdentify(socket, args)
|
||||
}
|
||||
}
|
||||
|
||||
function UpdateIntent(socket, args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// if i use a database in the future i need to consider that the lobby
|
||||
// name is not yet sanatised
|
||||
function LobbyCreate(socket, args)
|
||||
@@ -313,7 +325,3 @@ function LobbyUpdateCallback(user, lobby, state)
|
||||
});
|
||||
Game.Lobbies.IsLobbyReady(lobby.uid)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user