1 /*
2 * Copyright (C) 2004 Aaron
3 * Copyright (C) 2004 CreepLord (creeplord@pvpgn.org)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #include "common/setup_before.h"
20 #ifdef HAVE_STDDEF_H
21 # include <stddef.h>
22 #else
23 # ifndef NULL
24 # define NULL ((void *)0)
25 # endif
26 #endif
27 #ifdef STDC_HEADERS
28 # include <stdlib.h>
29 #else
30 # ifdef HAVE_MALLOC_H
31 # include <malloc.h>
32 # endif
33 #endif
34 #ifdef HAVE_STRING_H
35 # include <string.h>
36 #else
37 # ifdef HAVE_STRINGS_H
38 # include <strings.h>
39 # endif
40 #endif
41 #include <ctype.h>
42 #include "errno.h"
43 #include "compat/strerror.h"
44 #include "common/eventlog.h"
45 #include "common/tag.h"
46 #include "common/setup_after.h"
47
48 /* fixme: have all functions call tag_str_to_uint() */
clienttag_str_to_uint(char const * clienttag)49 extern t_clienttag clienttag_str_to_uint(char const * clienttag)
50 {
51 if (!clienttag)
52 {
53 eventlog(eventlog_level_error,__FUNCTION__,"got NULL clienttag");
54 return CLIENTTAG_UNKNOWN_UINT;
55 }
56
57 return tag_str_to_uint(clienttag);
58 }
59
60 /* fixme: have all fuctions call tag_uint_to_str() */
clienttag_uint_to_str(t_clienttag clienttag)61 extern char const * clienttag_uint_to_str(t_clienttag clienttag)
62 {
63 switch (clienttag)
64 {
65 case CLIENTTAG_BNCHATBOT_UINT:
66 return CLIENTTAG_BNCHATBOT;
67 case CLIENTTAG_STARCRAFT_UINT:
68 return CLIENTTAG_STARCRAFT;
69 case CLIENTTAG_BROODWARS_UINT:
70 return CLIENTTAG_BROODWARS;
71 case CLIENTTAG_SHAREWARE_UINT:
72 return CLIENTTAG_SHAREWARE;
73 case CLIENTTAG_DIABLORTL_UINT:
74 return CLIENTTAG_DIABLORTL;
75 case CLIENTTAG_DIABLOSHR_UINT:
76 return CLIENTTAG_DIABLOSHR;
77 case CLIENTTAG_WARCIIBNE_UINT:
78 return CLIENTTAG_WARCIIBNE;
79 case CLIENTTAG_DIABLO2DV_UINT:
80 return CLIENTTAG_DIABLO2DV;
81 case CLIENTTAG_STARJAPAN_UINT:
82 return CLIENTTAG_STARJAPAN;
83 case CLIENTTAG_DIABLO2ST_UINT:
84 return CLIENTTAG_DIABLO2ST;
85 case CLIENTTAG_DIABLO2XP_UINT:
86 return CLIENTTAG_DIABLO2XP;
87 case CLIENTTAG_WARCRAFT3_UINT:
88 return CLIENTTAG_WARCRAFT3;
89 case CLIENTTAG_WAR3XP_UINT:
90 return CLIENTTAG_WAR3XP;
91 case CLIENTTAG_IIRC_UINT:
92 return CLIENTTAG_IIRC;
93 case CLIENTTAG_WWOL_UINT:
94 return CLIENTTAG_WWOL;
95 default:
96 return CLIENTTAG_UNKNOWN;
97 }
98 }
99
100 /*****/
101 /* make all letters in string upper case - used in command.c*/
tag_case_str_to_uint(char const * tag_str)102 extern t_tag tag_case_str_to_uint(char const * tag_str)
103 {
104 unsigned int i, len;
105 char temp_str[5];
106
107 len = strlen(tag_str);
108 if (len != 4)
109 eventlog(eventlog_level_warn,__FUNCTION__,"got unusual sized clienttag '%s'",tag_str);
110
111 for (i=0; i<len && i < 4; i++)
112 if (islower((int)tag_str[i]))
113 temp_str[i] = toupper((int)tag_str[i]);
114 else
115 temp_str[i] = tag_str[i];
116
117 temp_str[4] = '\0';
118
119 return tag_str_to_uint(temp_str);
120 }
121
tag_str_to_uint(char const * tag_str)122 extern t_tag tag_str_to_uint(char const * tag_str)
123 {
124 t_tag tag_uint;
125
126 if (!tag_str) {
127 eventlog(eventlog_level_error,__FUNCTION__,"got NULL tag");
128 return 0; /* unknown */
129 }
130
131 tag_uint = tag_str[0]<<24;
132 tag_uint |= tag_str[1]<<16;
133 tag_uint |= tag_str[2]<< 8;
134 tag_uint |= tag_str[3] ;
135
136 return tag_uint;
137 }
138 /* tag_uint_to_str()
139 *
140 * from calling function:
141 *
142 * char tag_str[5]; // define first, then send into fuction
143 * tag_uint_to_str(tag_str, tag_uint); // returns pointer to tag_str
144 *
145 * Nothing to malloc, nothing to free
146 */
tag_uint_to_str(char * tag_str,t_tag tag_uint)147 extern char * tag_uint_to_str(char * tag_str, t_tag tag_uint)
148 {
149 if (!tag_uint) /* return "UNKN" if tag_uint = 0 */
150 return TAG_UNKNOWN;
151
152 tag_str[0] = ((unsigned char)(tag_uint>>24) );
153 tag_str[1] = ((unsigned char)(tag_uint>>16)&0xff);
154 tag_str[2] = ((unsigned char)(tag_uint>> 8)&0xff);
155 tag_str[3] = ((unsigned char)(tag_uint )&0xff);
156 tag_str[4] = '\0';
157 return tag_str;
158 }
159
tag_uint_to_revstr(char * tag_str,t_tag tag_uint)160 extern char * tag_uint_to_revstr(char * tag_str, t_tag tag_uint)
161 {
162 if (!tag_uint) /* return "UNKN" if tag_uint = 0 */
163 return TAG_UNKNOWN;
164
165 tag_str[0] = ((unsigned char)(tag_uint )&0xff);
166 tag_str[1] = ((unsigned char)(tag_uint>> 8)&0xff);
167 tag_str[2] = ((unsigned char)(tag_uint>>16)&0xff);
168 tag_str[3] = ((unsigned char)(tag_uint>>24) );
169 tag_str[4] = '\0';
170 return tag_str;
171 }
172
tag_check_arch(t_tag tag_uint)173 extern int tag_check_arch(t_tag tag_uint)
174 {
175 switch (tag_uint)
176 {
177 case ARCHTAG_WINX86_UINT:
178 case ARCHTAG_MACPPC_UINT:
179 case ARCHTAG_OSXPPC_UINT:
180 return 1;
181 default:
182 return 0;
183 }
184 }
185
tag_check_client(t_tag tag_uint)186 extern int tag_check_client(t_tag tag_uint)
187 {
188 switch (tag_uint)
189 {
190 case CLIENTTAG_BNCHATBOT_UINT:
191 case CLIENTTAG_STARCRAFT_UINT:
192 case CLIENTTAG_BROODWARS_UINT:
193 case CLIENTTAG_SHAREWARE_UINT:
194 case CLIENTTAG_DIABLORTL_UINT:
195 case CLIENTTAG_DIABLOSHR_UINT:
196 case CLIENTTAG_WARCIIBNE_UINT:
197 case CLIENTTAG_DIABLO2DV_UINT:
198 case CLIENTTAG_STARJAPAN_UINT:
199 case CLIENTTAG_DIABLO2ST_UINT:
200 case CLIENTTAG_DIABLO2XP_UINT:
201 case CLIENTTAG_WARCRAFT3_UINT:
202 case CLIENTTAG_WAR3XP_UINT:
203 case CLIENTTAG_IIRC_UINT:
204 case CLIENTTAG_WWOL_UINT:
205 return 1;
206 default:
207 return 0;
208 }
209 }
210
tag_check_gamelang(t_tag gamelang)211 extern int tag_check_gamelang(t_tag gamelang)
212 {
213 switch (gamelang)
214 {
215 case GAMELANG_ENGLISH_UINT: /* enUS */
216 case GAMELANG_GERMAN_UINT: /* deDE */
217 case GAMELANG_CZECH_UINT: /* csCZ */
218 case GAMELANG_SPANISH_UINT: /* esES */
219 case GAMELANG_FRENCH_UINT: /* frFR */
220 case GAMELANG_ITALIAN_UINT: /* itIT */
221 case GAMELANG_JAPANESE_UINT: /* jaJA */
222 case GAMELANG_KOREAN_UINT: /* koKR */
223 case GAMELANG_POLISH_UINT: /* plPL */
224 case GAMELANG_RUSSIAN_UINT: /* ruRU */
225 case GAMELANG_CHINESE_S_UINT: /* zhCN */
226 case GAMELANG_CHINESE_T_UINT: /* zhTW */
227 return 1;
228 default:
229 return 0;
230 }
231 }
232
clienttag_get_title(t_clienttag clienttag)233 extern char const * clienttag_get_title(t_clienttag clienttag)
234 {
235 switch (clienttag)
236 {
237 case CLIENTTAG_WAR3XP_UINT:
238 return "Warcraft III Frozen Throne";
239 case CLIENTTAG_WARCRAFT3_UINT:
240 return "Warcraft III";
241 case CLIENTTAG_DIABLO2XP_UINT:
242 return "Diablo II Lord of Destruction";
243 case CLIENTTAG_DIABLO2DV_UINT:
244 return "Diablo II";
245 case CLIENTTAG_STARJAPAN_UINT:
246 return "Starcraft (Japan)";
247 case CLIENTTAG_WARCIIBNE_UINT:
248 return "Warcraft II";
249 case CLIENTTAG_DIABLOSHR_UINT:
250 return "Diablo I (Shareware)";
251 case CLIENTTAG_DIABLORTL_UINT:
252 return "Diablo I";
253 case CLIENTTAG_SHAREWARE_UINT:
254 return "Starcraft (Shareware)";
255 case CLIENTTAG_BROODWARS_UINT:
256 return "Starcraft: Brood War";
257 case CLIENTTAG_STARCRAFT_UINT:
258 return "Starcraft";
259 case CLIENTTAG_BNCHATBOT_UINT:
260 return "Chat";
261 case CLIENTTAG_IIRC_UINT:
262 return "Internet Relay Chat";
263 case CLIENTTAG_WWOL_UINT:
264 return "Westwood Online";
265 default:
266 return "Unknown";
267 }
268 }
269
270