-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathaccount.c
executable file
·860 lines (757 loc) · 23.9 KB
/
account.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
/*/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
\
/ Luminari Account System, Inspired by D20mud's Account System
/ Created By: Ornir
\
/ using act.h as the header file currently
\ todo: move header stuff into account.h
/
\ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ /*/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "mysql.h"
#include "utils.h"
#include "db.h"
#include "handler.h"
#include "feats.h"
#include "dg_scripts.h"
#include "comm.h"
#include "interpreter.h"
#include "genmob.h"
#include "constants.h"
#include "spells.h"
#include "screen.h"
#include "class.h"
#include "act.h"
#include "account.h"
extern MYSQL *conn;
/* Forward reference */
void load_account_characters(struct account_data *account);
void load_account_unlocks(struct account_data *account);
#define Y TRUE
#define N FALSE
/* start functions! */
int locked_race_cost(int race)
{
return (race_list[race].unlock_cost);
}
bool is_locked_race(int race)
{
if (race_list[race].unlock_cost > 0)
return TRUE;
return FALSE;
}
int change_account_xp(struct char_data *ch, int change_val)
{
GET_ACCEXP_DESC(ch) += change_val;
if (GET_ACCEXP_DESC(ch) < 0)
GET_ACCEXP_DESC(ch) = 0;
if (GET_ACCEXP_DESC(ch) > 100000000)
GET_ACCEXP_DESC(ch) = 100000000;
save_account(ch->desc->account);
return GET_ACCEXP_DESC(ch);
}
int has_unlocked_race(struct char_data *ch, int race)
{
#if defined(CAMPAIGN_FR) || defined(CAMPAIGN_DL)
if (!ch || !ch->desc || !ch->desc->account)
#else
if (!ch || !ch->desc || !ch->desc->account || race == RACE_LICH || race == RACE_VAMPIRE)
#endif
return FALSE;
if (!is_locked_race(race))
return TRUE;
int i = 0;
for (i = 0; i < MAX_UNLOCKED_RACES; i++)
if (ch->desc->account->races[i] == race)
return TRUE;
return FALSE;
}
int has_unlocked_class(struct char_data *ch, int class)
{
if (!ch || !ch->desc || !ch->desc->account)
return FALSE;
if (!CLSLIST_LOCK(class))
return TRUE;
int i = 0;
for (i = 0; i < MAX_UNLOCKED_CLASSES; i++)
if (ch->desc->account->classes[i] == class)
return TRUE;
return FALSE;
}
#define ALIGN_COST 2000
ACMD(do_accexp)
{
char arg[MAX_INPUT_LENGTH] = {'\0'}, arg2[MAX_INPUT_LENGTH] = {'\0'};
int i = 0, j = 0;
int cost = 0;
int align_change = 100;
two_arguments(argument, arg, sizeof(arg), arg2, sizeof(arg2));
if (!*arg)
{
send_to_char(ch, "Usage: accexp [class | race | align] [<class-name to unlock> | "
"<race-name to unlock> | <evil OR good>]\r\n");
return;
}
if (is_abbrev(arg, "align"))
{
cost = ALIGN_COST;
if (!*arg2)
{
send_to_char(ch, "Please choose 'good' for good alignment change or 'evil' for evil alignment change. It cost %d account exp for each.\r\n", cost);
return;
}
if (is_abbrev(arg2, "evil"))
{
align_change *= -1;
}
else if (is_abbrev(arg2, "good"))
{
; /* base value above is fine */
}
else
{
send_to_char(ch, "Please choose 'good' for good alignment change or 'evil' for evil alignment change. It cost %d account exp for each.\r\n", cost);
return;
}
if (ch->desc && ch->desc->account)
{
if ((GET_ALIGNMENT(ch) + align_change) > 1099 || (GET_ALIGNMENT(ch) + align_change) < -1099)
{
send_to_char(ch, "You have the maximum alignment already!\r\n");
return;
}
else if (GET_ACCEXP_DESC(ch) >= cost)
{
change_account_xp(ch, -cost);
send_to_char(ch, "You have changed your alignment by %d points, costing %d account points!\r\n",
align_change, cost);
GET_ALIGNMENT(ch) += align_change;
if (GET_ALIGNMENT(ch) > 1000)
{
GET_ALIGNMENT(ch) = 1000;
send_to_char(ch, "You have the maximum good alignment now.\r\n");
}
if (GET_ALIGNMENT(ch) < -1000)
{
GET_ALIGNMENT(ch) = -1000;
send_to_char(ch, "You have the maximum evil alignment now.\r\n");
}
return;
}
else
{
send_to_char(ch, "You need %d account experience to purchase that change and you only have %d.\r\n",
cost, GET_ACCEXP_DESC(ch));
return;
}
}
else
{
send_to_char(ch, "There is a problem with your account and the item could "
"not be unlocked. Please submit a request to staff.\r\n");
return;
}
}
/* try to unlock a race */
else if (is_abbrev(arg, "race"))
{
if (!*arg2)
{
send_to_char(ch, "Please choose from the following races:\r\n");
#ifdef CAMPAIGN_FR
for (i = 0; i < NUM_EXTENDED_PC_RACES; i++)
#elif defined(CAMPAIGN_DL)
for (i = DL_RACE_START; i < DL_RACE_END; i++)
#else
for (i = 0; i < NUM_RACES; i++)
#endif
{
if (!is_locked_race(i) || has_unlocked_race(ch, i))
continue;
cost = locked_race_cost(i);
send_to_char(ch, "%s (%d account experience)\r\n", race_list[i].type, cost);
}
return;
}
#ifdef CAMPAIGN_FR
for (i = 0; i < NUM_EXTENDED_PC_RACES; i++)
#elif defined(CAMPAIGN_DL)
for (i = DL_RACE_START; i < DL_RACE_END; i++)
#else
for (i = 0; i < NUM_RACES; i++)
#endif
{
if (race_list[i].is_pc && is_abbrev(arg2, race_list[i].type) && is_locked_race(i) && !has_unlocked_race(ch, i))
{
cost = locked_race_cost(i);
break;
}
}
#ifdef CAMPAIGN_FR
if (i >= NUM_EXTENDED_PC_RACES)
#elif defined(CAMPAIGN_DL)
if (i >= DL_RACE_END)
#else
if (i >= NUM_RACES)
#endif
{
send_to_char(ch, "Either that race does not exist, is not an advanced race, "
"is not available for players, or you've already unlocked it.\r\n");
return;
}
if (ch->desc && ch->desc->account)
{
for (j = 0; j < MAX_UNLOCKED_RACES; j++)
{
if (ch->desc->account->races[j] == 0) /* race 0 is human, never locked */
break;
}
if (j >= MAX_UNLOCKED_RACES)
{
send_to_char(ch, "All of your advanced race slots are filled. Please "
"submit a petition to ask for the limit to be increased.\r\n");
return;
}
if (GET_ACCEXP_DESC(ch) >= cost)
{
ch->desc->account->races[j] = i;
send_to_char(ch, "You have unlocked the advanced race '%s' for all character "
"and future characters on your account!.\r\n",
race_list[i].type);
change_account_xp(ch, -cost); /* this will call save_account() for us */
return;
}
else
{
send_to_char(ch, "You need %d account experience to purchase that advanced "
"race and you only have %d.\r\n",
cost, GET_ACCEXP_DESC(ch));
return;
}
}
else
{
send_to_char(ch, "There is a problem with your account and the race could "
"not be unlocked. Please submit a request to staff.\r\n");
return;
}
/* try to unlock a locked class */
}
else if (is_abbrev(arg, "class"))
{
if (!*arg2)
{
send_to_char(ch, "Please choose from the following classes:\r\n");
for (i = 0; i < NUM_CLASSES; i++)
{
if (has_unlocked_class(ch, i) || !CLSLIST_LOCK(i))
continue;
#if defined(CAMPAIGN_DL)
cost = CLSLIST_COST(i) / 10;
#else
cost = CLSLIST_COST(i);
#endif
send_to_char(ch, "%s (%d account experience)\r\n", CLSLIST_NAME(i), cost);
}
return;
}
for (i = 0; i < NUM_CLASSES; i++)
{
if (is_abbrev(arg2, CLSLIST_NAME(i)) && !has_unlocked_class(ch, i) &&
CLSLIST_LOCK(i))
{
#if defined(CAMPAIGN_DL)
cost = CLSLIST_COST(i) / 10;
#else
cost = CLSLIST_COST(i);
#endif
break;
}
}
if (i >= NUM_CLASSES)
{
send_to_char(ch, "Either that class does not exist, is not a prestige class, "
"is not available for players, or you've already unlocked it.\r\n");
return;
}
if (ch->desc && ch->desc->account)
{
for (j = 0; j < MAX_UNLOCKED_CLASSES; j++)
{
if (ch->desc->account->classes[j] == 0) /* class 0 = wizard, never locked */
break;
}
if (j >= MAX_UNLOCKED_CLASSES)
{
send_to_char(ch, "All of your prestige class slots are filled. Please "
"Ask the staff for the limit to be increased.\r\n");
return;
}
if (GET_ACCEXP_DESC(ch) >= cost)
{
ch->desc->account->classes[j] = i;
send_to_char(ch, "You have unlocked the prestige class '%s' for all "
"character and future characters on your account!.\r\n",
CLSLIST_NAME(i));
change_account_xp(ch, -cost); /* this will call save_account() for us */
return;
}
else
{
send_to_char(ch, "You need %d account experience to purchase that prestige class and you only have %d.\r\n",
cost, GET_ACCEXP_DESC(ch));
return;
}
}
else
{
send_to_char(ch, "There is a problem with your account and the class could "
"not be unlocked. Please submit your issue to the staff.\r\n");
return;
}
}
else
{
send_to_char(ch, "You must choose to unlock either a race, class or alignment change.\r\n");
return;
}
}
int load_account(char *name, struct account_data *account)
{
MYSQL_RES *result;
MYSQL_ROW row;
char buf[2048];
/* Check if the account has data, if so, clear it. */
/* if (account != NULL) {
if (account->name != NULL)
free(account->name);
if (account->email != NULL)
free(account->email);
for (i = 0; i < MAX_CHARS_PER_ACCOUNT; i++)
if (account->character_names[i] != NULL)
free(account->character_names[i]);
}
*/
/* Check the connection, reconnect if necessary. */
mysql_ping(conn);
snprintf(buf, sizeof(buf), "SELECT id, name, password, experience, email from account_data where lower(name) = lower('%s')",
name);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to SELECT from account_data: %s", mysql_error(conn));
return -1;
}
if (!(result = mysql_store_result(conn)))
{
log("SYSERR: Unable to SELECT from account_data: %s", mysql_error(conn));
return -1;
}
if (!(row = mysql_fetch_row(result)))
return -1; /* Account not found. */
account->id = atoi(row[0]);
account->name = strdup(row[1]);
strncpy(account->password, row[2], MAX_PWD_LENGTH + 1);
account->experience = atoi(row[3]);
account->email = (row[4] ? strdup(row[4]) : NULL);
mysql_free_result(result);
load_account_characters(account);
load_account_unlocks(account);
return (0);
}
void load_account_characters(struct account_data *account)
{
MYSQL_RES *result;
MYSQL_ROW row;
char buf[2048];
int i = 0;
for (i = 0; i < MAX_CHARS_PER_ACCOUNT; i++)
if (account->character_names[i] != NULL)
{
free(account->character_names[i]);
account->character_names[i] = NULL;
}
snprintf(buf, sizeof(buf), "select name from player_data where account_id = %d", account->id);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to SELECT from player_data: %s", mysql_error(conn));
return;
}
if (!(result = mysql_store_result(conn)))
{
log("SYSERR: Unable to SELECT from player_data: %s", mysql_error(conn));
return;
}
i = 0;
while ((row = mysql_fetch_row(result)))
{
account->character_names[i] = strdup(row[0]);
i++;
}
if (result)
mysql_free_result(result);
return;
}
void load_account_unlocks(struct account_data *account)
{
MYSQL_RES *result;
MYSQL_ROW row;
char buf[2048];
int i = 0;
/* load locked classes */
snprintf(buf, sizeof(buf), "SELECT class_id from unlocked_classes "
"WHERE account_id = %d",
account->id);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to SELECT from unlocked_classes: %s", mysql_error(conn));
return;
}
if (!(result = mysql_store_result(conn)))
{
log("SYSERR: Unable to SELECT from unlocked_classes: %s", mysql_error(conn));
return;
}
i = 0;
while ((row = mysql_fetch_row(result)))
{
account->classes[i] = atoi(row[0]);
i++;
}
/* load locked races */
snprintf(buf, sizeof(buf), "SELECT race_id from unlocked_races "
"WHERE account_id = %d",
account->id);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to SELECT from unlocked_races: %s", mysql_error(conn));
return;
}
if (!(result = mysql_store_result(conn)))
{
log("SYSERR: Unable to SELECT from unlocked_races: %s", mysql_error(conn));
return;
}
i = 0;
while ((row = mysql_fetch_row(result)))
{
account->races[i] = atoi(row[0]);
i++;
}
/* cleanup */
mysql_free_result(result);
return;
}
char *get_char_account_name(char *name)
{
MYSQL_RES *result;
MYSQL_ROW row;
char buf[2048];
char *acct_name = NULL;
snprintf(buf, sizeof(buf), "select a.name from account_data a, player_data p where p.account_id = a.id and p.name = '%s'", name);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to retrieve account name for character %s: %s", name, mysql_error(conn));
return NULL;
}
if (!(result = mysql_store_result(conn)))
{
log("SYSERR: Unable to retreive account name for character %s: %s", name, mysql_error(conn));
return NULL;
}
while ((row = mysql_fetch_row(result)))
acct_name = (row[0] ? strdup(row[0]) : NULL);
mysql_free_result(result);
return acct_name;
}
void save_account(struct account_data *account)
{
char buf[2048];
int i = 0;
struct descriptor_data *j, *next_desc;
if (account == NULL)
{
log("SYSERR: Attempted to save NULL account.");
return;
}
snprintf(buf, sizeof(buf), "INSERT into account_data (id, name, password, experience, email) values (%d, '%s', '%s', %d, %s%s%s)"
" on duplicate key update password = VALUES(password), "
" experience = VALUES(experience), "
" email = VALUES(email);",
account->id,
account->name,
account->password,
account->experience,
(account->email ? "'" : ""),
(account->email ? account->email : "NULL"),
(account->email ? "'" : ""));
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to UPSERT into account_data: %s", mysql_error(conn));
return;
}
if (account->id == 0) /* This is a new account! */
account->id = mysql_insert_id(conn);
for (i = 0; (i < MAX_CHARS_PER_ACCOUNT) && (account->character_names[i] != NULL); i++)
{
buf[0] = '\0';
snprintf(buf, sizeof(buf), "INSERT into player_data (name, account_id) "
"VALUES('%s', %d) "
"on duplicate key update account_id = VALUES(account_id);",
account->character_names[i], account->id);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to UPSERT player_data: %s", mysql_error(conn));
return;
}
}
/* save unlocked races */
for (i = 0; i < MAX_UNLOCKED_RACES; i++)
{
buf[0] = '\0';
snprintf(buf, sizeof(buf), "INSERT into unlocked_races (account_id, race_id) "
"VALUES (%d, %d)"
"on duplicate key update race_id = VALUES(race_id);",
account->id, account->races[i]);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to UPSERT unlocked_races: %s", mysql_error(conn));
return;
}
}
/* save unlocked classes */
for (i = 0; i < MAX_UNLOCKED_CLASSES; i++)
{
buf[0] = '\0';
snprintf(buf, sizeof(buf), "INSERT into unlocked_classes (account_id, class_id) "
"VALUES (%d, %d)"
"on duplicate key update class_id = VALUES(class_id);",
account->id, account->classes[i]);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to UPSERT unlocked_classes: %s", mysql_error(conn));
return;
}
}
/* what happens if you have multiple characters logged on at the same time?
We need to update all characters in game with this account id */
for (j = descriptor_list; j; j = next_desc)
{
next_desc = j->next;
if (j->account)
{
if (j->account->id == account->id)
{
load_account_unlocks(j->account);
if (IS_PLAYING(j))
GET_ACCEXP_DESC(j->character) = account->experience;
}
}
}
}
void show_account_menu(struct descriptor_data *d)
{
int i = 0;
struct char_data *tch = NULL, *xtch = NULL;
char buf[MAX_STRING_LENGTH] = {'\0'};
size_t len = 0;
write_to_output(d, "\tC%s\tn", text_line_string("", 80, '-', '-'));
write_to_output(d, " \tc# \tC| \tcName \tC| \tcLvl \tC| \tcRace \tC| \tcClass\tn \r\n");
write_to_output(d, "\tC%s\tn", text_line_string("", 80, '-', '-'));
/* Check the connection, reconnect if necessary. */
mysql_ping(conn);
MYSQL_RES *res = NULL;
MYSQL_ROW row = NULL;
char query[MAX_INPUT_LENGTH] = {'\0'};
if (d->account)
{
for (i = 0; i < MAX_CHARS_PER_ACCOUNT; i++)
{
/* trying: Initialize a place for the player data to temporarially reside. -zusuk */
CREATE(xtch, struct char_data, 1);
clear_char(xtch);
CREATE(xtch->player_specials, struct player_special_data, 1);
new_mobile_data(xtch);
if (d->account->character_names[i] != NULL && load_char(d->account->character_names[i], xtch) > -1)
{
free_char(xtch);
write_to_output(d, " \tW%-3d\tn \tC|\tn \tW%-20s\tn\tC|\tn", i + 1, d->account->character_names[i]);
snprintf(query, sizeof(query), "SELECT name FROM player_data WHERE lower(name)=lower('%s')", d->account->character_names[i]);
if (mysql_query(conn, query))
{
log("SYSERR: Unable to SELECT from player_data: %s", mysql_error(conn));
}
if (!(res = mysql_store_result(conn)))
{
log("SYSERR: Unable to SELECT from player_data: %s", mysql_error(conn));
}
if (res != NULL)
{
if ((row = mysql_fetch_row(res)) != NULL)
{
/* Initialize a place for the player data to temporarially reside. */
CREATE(tch, struct char_data, 1);
clear_char(tch);
CREATE(tch->player_specials, struct player_special_data, 1);
new_mobile_data(tch);
if ((load_char(d->account->character_names[i], tch)) > -1)
{
/* Player found! */
if (PLR_FLAGGED(tch, PLR_DELETED))
{
write_to_output(d, " \tR---===||DELETED||===---\tn\r\n");
return;
}
write_to_output(d, " %3d \tC|\tn %4s \tC|\tn", GET_LEVEL(tch), race_list[GET_REAL_RACE(tch)].abbrev_color);
if (GET_LEVEL(tch) >= LVL_IMMORT)
{
/* Staff */
write_to_output(d, " %-36s", admin_level_names[(GET_LEVEL(tch) - LVL_IMMORT)]);
}
else
{
/* Mortal */
int inc, classCount = 0;
buf[0] = '\0';
len = 0;
for (inc = 0; inc < MAX_CLASSES; inc++)
{
if (CLASS_LEVEL(tch, inc))
{
if (classCount)
len += snprintf(buf + len, sizeof(buf) - len, "/");
len += snprintf(buf + len, sizeof(buf) - len, "%s",
CLSLIST_CLRABBRV(inc));
classCount++;
}
}
write_to_output(d, " %-36s", buf);
}
}
free_char(tch);
}
}
mysql_free_result(res);
write_to_output(d, "\r\n");
}
}
}
write_to_output(d, "You can view more info about your account by typing "
"'account' in-game.\r\n");
write_to_output(d, "\tC%s\tn", text_line_string("", 80, '-', '-'));
write_to_output(d, "\tcType the # of a character listed above or choose one of the following:\r\n");
write_to_output(d, "\tC%s\tn", text_line_string("", 80, '-', '-'));
write_to_output(d, " \tn(\tCC\tn)\tcreate a new character \tC| \tn(\tCA\tn)\tcdd a character \tC| \tn(\tCQ\tn)\tcuit\tn\r\n");
write_to_output(d, "\tC%s\tn", text_line_string("", 80, '-', '-'));
write_to_output(d, "\tcYour choice :\tn ");
/* Set this here so we don't have to do it everywhere this procedure is called. */
STATE(d) = CON_ACCOUNT_MENU;
}
/*
void combine_accounts(void) {
struct descriptor_data *d;
struct descriptor_data *k;
for (d = descriptor_list; d; d = d->next) {
for (k = descriptor_list; k; k = k->next) {
if (d && k && d->account && k->account && d->account != k->account &&
d->character && k->character && d->character->account_name && k->character->account_name &&
!strcmp(d->character->account_name, k->character->account_name)) {
d->account = k->account;
return;
}
}
}
}
*/
/* engine for ACMDU(do_account) */
void perform_do_account(struct char_data *ch, struct char_data *vict)
{
bool found = FALSE;
int i = 0;
if (IS_NPC(vict) || !vict->desc || !vict->desc->account)
{
send_to_char(ch, "The account command can only be used by player characters "
"with a valid account.\r\n");
return;
}
struct account_data *acc = vict->desc->account;
send_to_char(ch, "\tC");
draw_line(ch, 80, '-', '-');
send_to_char(ch,
"\tcAccount Information for \tW%s\tc\r\n",
acc->name);
send_to_char(ch, "\tC");
draw_line(ch, 80, '-', '-');
send_to_char(ch,
"\tcEmail: \tn%s\r\n"
// "Level: %d\r\n"
"\tcExperience: \tn%d (notice: this caps at 100mil)\r\n"
// "Gift Experience: %d\r\n"
// "Web Site Password: %s\r\n"
"\tcCharacters:\tn\r\n",
(acc->email ? acc->email : "\trNot Set\tn"), acc->experience);
for (i = 0; i < MAX_CHARS_PER_ACCOUNT; i++)
{
if (acc->character_names[i] != NULL)
send_to_char(ch, " \tn%s\r\n", acc->character_names[i]);
}
/* show unlocked races */
send_to_char(ch, "Unlocked Races:\r\n");
for (i = 0; i < MAX_UNLOCKED_RACES; i++)
{
if (acc->races[i] != 0)
{
send_to_char(ch, " %s\r\n", race_list[acc->races[i]].type);
found = TRUE;
}
}
if (!found)
send_to_char(ch, " None.\r\n");
/* show unlocked classes */
found = FALSE;
send_to_char(ch, "Unlocked Classes:\r\n");
for (i = 0; i < MAX_UNLOCKED_CLASSES; i++)
{
if (acc->classes[i] != 0)
{
send_to_char(ch, " %s\r\n", CLSLIST_NAME(acc->classes[i]));
found = TRUE;
}
}
if (!found)
send_to_char(ch, " None.\r\n");
if (ch == vict)
send_to_char(ch, "You can unlock races and classes via the 'accexp' command.\r\n");
send_to_char(ch, "\tC");
draw_line(ch, 80, '-', '-');
}
ACMD(do_account)
{
perform_do_account(ch, ch);
}
/* Remove the player from the database, so that accounts do not reference it. */
void remove_char_from_account(struct char_data *ch, struct account_data *account)
{
char buf[2048];
if (ch == NULL)
{
log("SYSERR: Tried to remove a NULL char from account!");
return;
}
else if (account == NULL)
{
log("SYSERR: Tried to remove a character from a NULL account!");
return;
}
snprintf(buf, sizeof(buf), "DELETE from player_data where lower(name) = lower('%s') and account_id = %d;",
GET_NAME(ch), account->id);
if (mysql_query(conn, buf))
{
log("SYSERR: Unable to DELETE from player_data: %s", mysql_error(conn));
return;
}
/* Reload the character names */
load_account_characters(account);
log("INFO: Character %s removed from account %s : %s", GET_NAME(ch), account->name, mysql_info(conn));
}