implemented channels on server
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "responses.h"
|
||||
|
||||
#define LOGGER conn->server->logger
|
||||
#define LOG_FUNC conn->server->log_func
|
||||
#define srv conn->server
|
||||
#define LOGGER srv->logger
|
||||
#define LOG_FUNC srv->log_func
|
||||
#define LOG_CONTEXT log_ctx
|
||||
|
||||
declare_RequestHandler(Login)
|
||||
@@ -35,15 +36,15 @@ declare_RequestHandler(Login)
|
||||
}
|
||||
|
||||
// lock users cache
|
||||
idb_lockTable(conn->server->users.table);
|
||||
idb_lockTable(srv->users.table);
|
||||
bool unlocked_users_cache_mutex = false;
|
||||
Defer(
|
||||
if(!unlocked_users_cache_mutex)
|
||||
idb_unlockTable(conn->server->users.table)
|
||||
idb_unlockTable(srv->users.table)
|
||||
);
|
||||
|
||||
// try get id from name cache
|
||||
u64* id_ptr = HashMap_tryGetPtr(&conn->server->users.username_id_map, username_str);
|
||||
u64* id_ptr = HashMap_tryGetPtr(&srv->users.name_id_map, username_str);
|
||||
if(id_ptr == NULL){
|
||||
try_void(sendErrorMessage_f(log_ctx, conn, res_head,
|
||||
LogSeverity_Warn,
|
||||
@@ -55,8 +56,8 @@ declare_RequestHandler(Login)
|
||||
u64 user_id = *id_ptr;
|
||||
|
||||
// get user by id
|
||||
try_assert(user_id < conn->server->users.cache_list.len);
|
||||
UserInfo* u = conn->server->users.cache_list.data + user_id;
|
||||
try_assert(user_id < srv->users.list.len);
|
||||
UserInfo* u = srv->users.list.data + user_id;
|
||||
|
||||
// validate token hash
|
||||
if(memcmp(req.token, u->token, sizeof(req.token)) != 0){
|
||||
@@ -68,16 +69,17 @@ declare_RequestHandler(Login)
|
||||
}
|
||||
|
||||
// manually unlock mutex
|
||||
idb_unlockTable(conn->server->users.table);
|
||||
idb_unlockTable(srv->users.table);
|
||||
unlocked_users_cache_mutex = true;
|
||||
|
||||
// authorize
|
||||
conn->authorized = true;
|
||||
conn->user_id = user_id;
|
||||
logInfo("authorized user '%s'", username_str.data);
|
||||
|
||||
// send response
|
||||
LoginResponse res;
|
||||
LoginResponse_construct(&res, res_head, user_id, conn->server->landing_channel_id);
|
||||
LoginResponse_construct(&res, res_head, user_id, srv->landing_channel_id);
|
||||
try_void(EncryptedSocketTCP_sendStruct(&conn->sock, res_head));
|
||||
try_void(EncryptedSocketTCP_sendStruct(&conn->sock, &res));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user