2021-07-13 07:34:34 +00:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include "util.h"
|
|
|
|
#include "cart.h"
|
|
|
|
#include "realm.h"
|
|
|
|
#include "user.h"
|
|
|
|
|
|
|
|
extern UserInfo users_table[64];
|
|
|
|
|
|
|
|
UserInfo* find_user(UserInfo* table, char* uname) {
|
|
|
|
UserInfo* u = table;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
if (scmp(uname, u->name))
|
|
|
|
return u;
|
|
|
|
u++;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_cart(UserInfo* table, char* uname, char* cart_name) {
|
|
|
|
Cart* c = find_cart(table, cart_name);
|
|
|
|
UserInfo* u = find_user(table, uname);
|
|
|
|
|
|
|
|
if (u == nil)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (c != nil) {
|
|
|
|
u->cart = c;
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
u->cart = create_cart(cart_name);
|
|
|
|
if (u->cart == nil)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int enter_realm(UserInfo* table, char* uname, char* realm_name) {
|
|
|
|
Realm* r = find_realm(table, realm_name);
|
|
|
|
UserInfo* u = find_user(table, uname);
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (u == nil || u->cart == nil)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = j = 0; i < 64; i++) {
|
|
|
|
if (table[i].realm != nil && scmp(table[i].realm->name, realm_name))
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
if (j >= r->max)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (r != nil) {
|
|
|
|
u->realm = r;
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
u->realm = parse_realm(realm_name);
|
|
|
|
if (u->realm == nil)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int leave_realm(UserInfo* table, char* uname) {
|
|
|
|
UserInfo* u = find_user(table, uname);
|
|
|
|
Realm* r;
|
|
|
|
|
|
|
|
if (u == nil)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = u->realm;
|
|
|
|
if (r == nil)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
save_realm(r);
|
|
|
|
u->realm = nil;
|
|
|
|
if (find_realm(table, r->name) == nil)
|
|
|
|
destroy_realm(r);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unload_cart(UserInfo* table, char* uname) {
|
|
|
|
UserInfo* u = find_user(table, uname);
|
|
|
|
Cart* c;
|
|
|
|
|
|
|
|
if (u == nil)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
c = u->cart;
|
|
|
|
if (c == nil)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
u->cart = nil;
|
|
|
|
if (find_cart(table, c->name) == nil)
|
|
|
|
destroy_cart(c);
|
|
|
|
return 1;
|
|
|
|
}
|