forked from zid/Diablo-MUD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.c
76 lines (61 loc) · 1.21 KB
/
character.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "rooms.h"
#include "character.h"
#include "client.h"
struct character {
char *username;
struct client *c;
room *r;
};
void character_prompt(character *ch)
{
client_prompt(ch->c);
}
void chprintf(character *ch, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vcprintf(ch->c, fmt, ap);
va_end(ap);
}
void character_login(client *c)
{
character *ch;
ch = client_character(c);
room_add_character(ch->r, ch, ROOM_LOGIN);
}
room *character_room(character *ch)
{
return ch->r;
}
character *character_init(client *c)
{
character *ch;
ch = malloc(sizeof(character));
/* For now, just shove everybody in the plaza when they connect */
ch->r = room_get("plaza");
/* Backreference to the controlling client, to assist in lookups */
ch->c = c;
return ch;
}
void character_set_username(character *ch, char const *username)
{
ch->username = strdup(username);
}
const char *character_username(character *ch)
{
return ch->username;
}
const char *character_room_name(character *ch)
{
return room_name(ch->r);
}
void character_free(character *ch)
{
room_del_character(ch->r, ch, ROOM_LOGOUT);
free(ch->username);
free(ch);
}