1 /* world server - copyright 2002 evileye
2  *
3  */
4 
5 #include <stdint.h>
6 
7 #define MSG_LEN 256
8 
9 #define MAX_LTTL	20	/* Max TTL for temporary locks */
10 
11 #define MAX_SERVERS	30	/* Max servers we will deal */
12 
13 /* World packet types */
14 #define WP_CHAT		1	/* chat message */
15 #define WP_NPLAYER	2	/* player enters */
16 #define WP_QPLAYER	3	/* player leaves */
17 #define WP_DEATH	4	/* player death */
18 #define WP_LOCK		5	/* obtain a lock (timed) */
19 #define WP_UNLOCK	6	/* free the lock */
20 #define WP_MESSAGE	7	/* all critical server messages */
21 #define WP_AUTH		8	/* server authing */
22 #define WP_SQUIT	9	/* server quits */
23 #define WP_RESTART	10	/* servers quit now */
24 #define WP_LACCOUNT	11	/* login account */
25 #define WP_PMSG		12	/* private message */
26 #define WP_SINFO	13	/* server info */
27 #define WP_IRCCHAT	14	/* chat message directed to a particular server (irc-relay) */
28 #define WP_MSG_TO_IRC	15	/* chat message to IRC channel only (not to other game servers) */
29 
30 /* World packet flags */
31 #define WPF_CHAT	0x0001	/* chat message - C */
32 #define WPF_NPLAYER	0x0002	/* player enters - N */
33 #define WPF_QPLAYER	0x0004	/* player leaves - Q */
34 #define WPF_DEATH	0x0008	/* player death - D */
35 #define WPF_LOCK	0x0010
36 #define WPF_UNLOCK	0x0020
37 #define WPF_MESSAGE	0x0040	/* all critical server messages - M */
38 #define WPF_AUTH	0x0080
39 #define WPF_SQUIT	0x0100
40 #define WPF_RESTART	0x0200
41 #define WPF_LACCOUNT	0x0400
42 #define WPF_PMSG	0x0800	/* private message - P */
43 #define WPF_SINFO	0x1000
44 #define WPF_IRCCHAT	0x2000	/* chat message from IRC relay - S */
45 
46 /* World message flags */
47 #define WMF_LVLUP	0x01
48 #define WMF_UNIDEATH	0x02
49 #define WMF_PWIN	0x04
50 #define WMF_HILVLUP	0x08
51 #define WMF_PDEATH	0x10
52 #define WMF_PJOIN	0x20
53 #define WMF_PLEAVE	0x40
54 #define WMF_EVENTS	0x80
55 
56 /* now we are going to be the server which authenticates
57  * the players. Once they are logged in, they will receive
58  * a key which will enable to pass worlds without needing
59  * to be reauthenticated
60  */
61 
62 #define CL_QUIT		1
63 
64 struct serverinfo{
65 	char name[20];		/* server world name */
66 	char pass[20];		/* server plaintext password */
67 	uint32_t rflags;	/* relay flags for packets sent to server */
68 	uint32_t mflags;	/* messages flags */
69 };
70 
71 /* Single linked list - its not like we are sorting it */
72 struct list{
73 	struct list *next;
74 	void *data;		/* pointer to the data structure */
75 };
76 
77 struct rplist{
78 	uint32_t id;
79 	int16_t server;
80 	char name[30];
81 };
82 
83 /* linked list will use less mem */
84 struct objlock{
85 	int16_t owner;		/* Owner ID */
86 	uint32_t ttl;	/* time to live for non final lock */
87 	uint32_t obj;	/* lock object by number (monster, item etc.) */
88 };
89 
90 struct client{
91 	int fd;
92 	uint16_t flags;
93 	int16_t authed;		/* Server ID (>0), authing (0), or failed authentication (-1) */
94 	uint16_t blen;
95 	char buf[1024];
96 };
97 
98 struct secure{
99 	int16_t secure;	/* kick off ALL unauthed clients */
100 	int16_t chat;	/* Permit chat if unauthed (and not secure) */
101 	int16_t play;	/* Players online messages (no tracing on unauthed) */
102 	int16_t msgs;	/* Permit server messages */
103 };
104 
105 /* The structures of these packets will be
106    changed when we merge data */
107 
108 struct player{
109 	uint32_t id;	/* UNIQUE player id */
110 	uint16_t server;		/* server info 0 means unknown */
111 	char name[30];		/* temp. player name */
112 	uint8_t silent;	/* Left due to death for instance */
113 };
114 
115 struct death{
116 	uint32_t id;
117 	uint16_t dtype;	/* death type */
118 	char name[30];		/* temp. player name */
119 	char method[40];	/* death method */
120 };
121 
122 struct chat{
123 	uint32_t id;	/* From ID */
124 	char ctxt[MSG_LEN];
125 };
126 
127 struct pmsg{
128 	uint32_t id;	/* From ID */
129 	uint16_t sid;	/* To server ID */
130 	char player[80];	/* thats what it is in server :( */
131 	char victim[80];	/* thats what it is in server :( */
132 	char ctxt[MSG_LEN];
133 };
134 
135 struct sinfo{
136 	uint16_t sid;
137 	uint16_t port;	/* needed for client transfers */
138 	char name[30];
139 };
140 
141 
142 /* server world authentication */
143 struct auth{
144 	char pass[21];
145 	uint32_t val;
146 };
147 
148 #define PL_INIT	1	/* init from client with password */
149 #define PL_OK	2	/* from server */
150 #define PL_FAIL	3	/* auth fail */
151 #define PL_USED	4	/* char name is owned */
152 #define PL_DUP	5	/* logged in already */
153 #define PL_QUERY 6	/* query from client */
154 
155 /* identical to struct account */
156 /* only AUTHED servers can do this */
157 struct pl_auth{
158 	uint32_t id;	/* account id */
159 	uint16_t flags;	/* account flags */
160 	uint16_t stat;	/* status (for return) */
161 	char name[30];	/* login */
162 	char pass[20];	/* some crypts are not 13 */
163 	char pname[80];	/* player character name */
164 };
165 
166 #define LT_ARTIFACT	1
167 #define LT_MONSTER	2	/* not sure how i'm gonna do this yet */
168 
169 struct lock{
170 	uint16_t ltype;	/* Lock type */
171 	uint32_t ttl;	/* time to live for non final lock */
172 	uint32_t obj;	/* lock object by number (monster, item etc.) */
173 };
174 
175 struct smsg{
176 	char stxt[MSG_LEN];		/* may need more info than this sometime */
177 };
178 
179 struct wpacket{
180 	uint16_t type;	/* TYPE */
181 	uint16_t serverid;
182 	union {
183 		int16_t sid;
184 		struct chat chat;
185 		struct smsg smsg;
186 		struct player play;
187 		struct auth auth;
188 		struct lock lock;
189 		struct pmsg pmsg;
190 		struct pl_auth login;
191 		struct sinfo sinfo;
192 	} d;
193 };
194