1 | // (c) eAthena Dev Team - Licensed under GNU GPL |
---|
2 | // For more information, see LICENCE in the main folder |
---|
3 | |
---|
4 | #include "../common/cbasetypes.h" |
---|
5 | #include "../common/mmo.h" |
---|
6 | #include "../common/core.h" |
---|
7 | #include "../common/strlib.h" |
---|
8 | #include "../common/showmsg.h" |
---|
9 | #include "../common/mapindex.h" |
---|
10 | #include "../common/utils.h" |
---|
11 | |
---|
12 | #include "../char/char.h" |
---|
13 | #include "../char/int_storage.h" |
---|
14 | #include "../char/int_pet.h" |
---|
15 | #include "../char/int_party.h" |
---|
16 | #include "../char/int_guild.h" |
---|
17 | #include "../char/inter.h" |
---|
18 | |
---|
19 | #include "../char_sql/char.h" |
---|
20 | #include "../char_sql/int_storage.h" |
---|
21 | #include "../char_sql/int_pet.h" |
---|
22 | #include "../char_sql/int_party.h" |
---|
23 | #include "../char_sql/int_guild.h" |
---|
24 | #include "../char_sql/inter.h" |
---|
25 | |
---|
26 | #include <stdio.h> |
---|
27 | #include <stdlib.h> |
---|
28 | #include <string.h> |
---|
29 | |
---|
30 | #define CHAR_CONF_NAME "conf/char_athena.conf" |
---|
31 | #define SQL_CONF_NAME "conf/inter_athena.conf" |
---|
32 | #define INTER_CONF_NAME "conf/inter_athena.conf" |
---|
33 | //-------------------------------------------------------- |
---|
34 | |
---|
35 | int convert_init(void) |
---|
36 | { |
---|
37 | char line[65536]; |
---|
38 | int ret; |
---|
39 | int set,tmp_int[2], lineno, count; |
---|
40 | char input; |
---|
41 | FILE *fp; |
---|
42 | |
---|
43 | ShowWarning("Make sure you backup your databases before continuing!\n"); |
---|
44 | ShowMessage("\n"); |
---|
45 | |
---|
46 | ShowNotice("Do you wish to convert your Character Database to SQL? (y/n) : "); |
---|
47 | input = getchar(); |
---|
48 | if(input == 'y' || input == 'Y') |
---|
49 | { |
---|
50 | struct character_data char_dat; |
---|
51 | struct accreg reg; |
---|
52 | |
---|
53 | ShowStatus("Converting Character Database...\n"); |
---|
54 | if( (fp = fopen(char_txt, "r")) == NULL ) |
---|
55 | { |
---|
56 | ShowError("Unable to open file [%s]!\n", char_txt); |
---|
57 | return 0; |
---|
58 | } |
---|
59 | lineno = count = 0; |
---|
60 | while(fgets(line, sizeof(line), fp)) |
---|
61 | { |
---|
62 | lineno++; |
---|
63 | memset(&char_dat, 0, sizeof(struct character_data)); |
---|
64 | ret=mmo_char_fromstr(line, &char_dat.status, char_dat.global, &char_dat.global_num); |
---|
65 | if(ret > 0) { |
---|
66 | count++; |
---|
67 | parse_friend_txt(&char_dat.status); //Retrieve friends. |
---|
68 | mmo_char_tosql(char_dat.status.char_id , &char_dat.status); |
---|
69 | |
---|
70 | memset(®, 0, sizeof(reg)); |
---|
71 | reg.account_id = char_dat.status.account_id; |
---|
72 | reg.char_id = char_dat.status.char_id; |
---|
73 | reg.reg_num = char_dat.global_num; |
---|
74 | memcpy(®.reg, &char_dat.global, reg.reg_num*sizeof(struct global_reg)); |
---|
75 | inter_accreg_tosql(reg.account_id, reg.char_id, ®, 3); //Type 3: Character regs |
---|
76 | } else { |
---|
77 | ShowError("Error %d converting character line [%s] (at %s:%d).\n", ret, line, char_txt, lineno); |
---|
78 | } |
---|
79 | } |
---|
80 | ShowStatus("Converted %d characters.\n", count); |
---|
81 | fclose(fp); |
---|
82 | ShowStatus("Converting Account variables Database...\n"); |
---|
83 | if( (fp = fopen(accreg_txt, "r")) == NULL ) |
---|
84 | { |
---|
85 | ShowError("Unable to open file %s!", accreg_txt); |
---|
86 | return 1; |
---|
87 | } |
---|
88 | lineno = count = 0; |
---|
89 | while(fgets(line, sizeof(line), fp)) |
---|
90 | { |
---|
91 | lineno++; |
---|
92 | memset (®, 0, sizeof(struct accreg)); |
---|
93 | if(inter_accreg_fromstr(line, ®) == 0 && reg.account_id > 0) { |
---|
94 | count++; |
---|
95 | inter_accreg_tosql(reg.account_id, 0, ®, 2); //Type 2: Account regs |
---|
96 | } else { |
---|
97 | ShowError("accreg reading: broken data [%s] at %s:%d\n", line, accreg_txt, lineno); |
---|
98 | } |
---|
99 | } |
---|
100 | ShowStatus("Converted %d account registries.\n", count); |
---|
101 | fclose(fp); |
---|
102 | } |
---|
103 | |
---|
104 | while(getchar() != '\n'); |
---|
105 | ShowMessage("\n"); |
---|
106 | ShowNotice("Do you wish to convert your Storage Database to SQL? (y/n) : "); |
---|
107 | input = getchar(); |
---|
108 | if(input == 'y' || input == 'Y') |
---|
109 | { |
---|
110 | struct storage storage_; |
---|
111 | ShowMessage("\n"); |
---|
112 | ShowStatus("Converting Storage Database...\n"); |
---|
113 | if( (fp = fopen(storage_txt,"r")) == NULL ) |
---|
114 | { |
---|
115 | ShowError("can't read : %s\n", storage_txt); |
---|
116 | return 0; |
---|
117 | } |
---|
118 | lineno = count = 0; |
---|
119 | while(fgets(line, sizeof(line), fp)) |
---|
120 | { |
---|
121 | lineno++; |
---|
122 | set=sscanf(line,"%d,%d",&tmp_int[0],&tmp_int[1]); |
---|
123 | if(set==2) { |
---|
124 | memset(&storage_, 0, sizeof(struct storage)); |
---|
125 | storage_.account_id=tmp_int[0]; |
---|
126 | if (storage_fromstr(line,&storage_) == 0) { |
---|
127 | count++; |
---|
128 | storage_tosql(storage_.account_id,&storage_); //to sql. (dump) |
---|
129 | } else { |
---|
130 | ShowError("Error parsing storage line [%s] (at %s:%d)\n", line, storage_txt, lineno); |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | ShowStatus("Converted %d storages.\n", count); |
---|
135 | fclose(fp); |
---|
136 | } |
---|
137 | |
---|
138 | //FIXME: CONVERT STATUS DATA HERE!!! |
---|
139 | |
---|
140 | while(getchar() != '\n'); |
---|
141 | ShowMessage("\n"); |
---|
142 | ShowNotice("Do you wish to convert your Pet Database to SQL? (y/n) : "); |
---|
143 | input=getchar(); |
---|
144 | if(input == 'y' || input == 'Y') |
---|
145 | { |
---|
146 | struct s_pet p; |
---|
147 | ShowMessage("\n"); |
---|
148 | ShowStatus("Converting Pet Database...\n"); |
---|
149 | if( (fp = fopen(pet_txt, "r")) == NULL ) |
---|
150 | { |
---|
151 | ShowError("Unable to open file %s!", pet_txt); |
---|
152 | return 1; |
---|
153 | } |
---|
154 | lineno = count = 0; |
---|
155 | while(fgets(line, sizeof(line), fp)) |
---|
156 | { |
---|
157 | lineno++; |
---|
158 | memset (&p, 0, sizeof(struct s_pet)); |
---|
159 | if(inter_pet_fromstr(line, &p)==0 && p.pet_id>0) { |
---|
160 | count++; |
---|
161 | inter_pet_tosql(p.pet_id,&p); |
---|
162 | } else { |
---|
163 | ShowError("pet reading: broken data [%s] at %s:%d\n", line, pet_txt, lineno); |
---|
164 | } |
---|
165 | } |
---|
166 | ShowStatus("Converted %d pets.\n", count); |
---|
167 | fclose(fp); |
---|
168 | } |
---|
169 | |
---|
170 | //FIXME: CONVERT HOMUNCULUS DATA AND SKILLS HERE!!! |
---|
171 | |
---|
172 | while(getchar() != '\n'); |
---|
173 | ShowMessage("\n"); |
---|
174 | ShowNotice("Do you wish to convert your Party Database to SQL? (y/n) : "); |
---|
175 | input=getchar(); |
---|
176 | if(input == 'y' || input == 'Y') |
---|
177 | { |
---|
178 | struct party p; |
---|
179 | ShowMessage("\n"); |
---|
180 | ShowStatus("Converting Party Database...\n"); |
---|
181 | if( (fp = fopen(party_txt, "r")) == NULL ) |
---|
182 | { |
---|
183 | ShowError("Unable to open file %s!", party_txt); |
---|
184 | return 1; |
---|
185 | } |
---|
186 | lineno = count = 0; |
---|
187 | while(fgets(line, sizeof(line), fp)) |
---|
188 | { |
---|
189 | lineno++; |
---|
190 | memset (&p, 0, sizeof(struct party)); |
---|
191 | if(inter_party_fromstr(line, &p) == 0 && |
---|
192 | p.party_id > 0 && |
---|
193 | inter_party_tosql(&p, PS_CREATE, 0)) |
---|
194 | count++; |
---|
195 | else{ |
---|
196 | ShowError("party reading: broken data [%s] at %s:%d\n", line, pet_txt, lineno); |
---|
197 | } |
---|
198 | } |
---|
199 | ShowStatus("Converted %d parties.\n", count); |
---|
200 | fclose(fp); |
---|
201 | } |
---|
202 | |
---|
203 | while(getchar() != '\n'); |
---|
204 | ShowMessage("\n"); |
---|
205 | ShowNotice("Do you wish to convert your Guilds and Castles Database to SQL? (y/n) : "); |
---|
206 | input=getchar(); |
---|
207 | if(input == 'y' || input == 'Y') |
---|
208 | { |
---|
209 | struct guild g; |
---|
210 | struct guild_castle gc; |
---|
211 | ShowMessage("\n"); |
---|
212 | ShowStatus("Converting Guild Database...\n"); |
---|
213 | if( (fp = fopen(guild_txt, "r")) == NULL ) |
---|
214 | { |
---|
215 | ShowError("Unable to open file %s!", guild_txt); |
---|
216 | return 1; |
---|
217 | } |
---|
218 | lineno = count = 0; |
---|
219 | while(fgets(line, sizeof(line), fp)) |
---|
220 | { |
---|
221 | lineno++; |
---|
222 | memset (&g, 0, sizeof(struct guild)); |
---|
223 | if (inter_guild_fromstr(line, &g) == 0 && |
---|
224 | g.guild_id > 0 && |
---|
225 | inter_guild_tosql(&g,GS_MASK)) |
---|
226 | count++; |
---|
227 | else |
---|
228 | ShowError("guild reading: broken data [%s] at %s:%d\n", line, guild_txt, lineno); |
---|
229 | } |
---|
230 | ShowStatus("Converted %d guilds.\n", count); |
---|
231 | fclose(fp); |
---|
232 | ShowStatus("Converting Guild Castles Database...\n"); |
---|
233 | if( (fp = fopen(castle_txt, "r")) == NULL ) |
---|
234 | { |
---|
235 | ShowError("Unable to open file %s!", castle_txt); |
---|
236 | return 1; |
---|
237 | } |
---|
238 | lineno = count = 0; |
---|
239 | while(fgets(line, sizeof(line), fp)) |
---|
240 | { |
---|
241 | lineno++; |
---|
242 | memset(&gc, 0, sizeof(struct guild_castle)); |
---|
243 | if (inter_guildcastle_fromstr(line, &gc) == 0) { |
---|
244 | inter_guildcastle_tosql(&gc); |
---|
245 | count++; |
---|
246 | } |
---|
247 | else |
---|
248 | ShowError("guild castle reading: broken data [%s] at %s:%d\n", line, castle_txt, lineno); |
---|
249 | } |
---|
250 | ShowStatus("Converted %d guild castles.\n", count); |
---|
251 | fclose(fp); |
---|
252 | } |
---|
253 | |
---|
254 | while(getchar() != '\n'); |
---|
255 | ShowMessage("\n"); |
---|
256 | ShowNotice("Do you wish to convert your Guild Storage Database to SQL? (y/n) : "); |
---|
257 | input=getchar(); |
---|
258 | if(input == 'y' || input == 'Y') |
---|
259 | { |
---|
260 | struct guild_storage storage_; |
---|
261 | ShowMessage("\n"); |
---|
262 | ShowStatus("Converting Guild Storage Database...\n"); |
---|
263 | if( (fp = fopen(guild_storage_txt, "r")) == NULL ) |
---|
264 | { |
---|
265 | ShowError("can't read : %s\n", guild_storage_txt); |
---|
266 | return 0; |
---|
267 | } |
---|
268 | lineno = count = 0; |
---|
269 | while(fgets(line, sizeof(line), fp)) |
---|
270 | { |
---|
271 | lineno++; |
---|
272 | memset(&storage_, 0, sizeof(struct guild_storage)); |
---|
273 | if (sscanf(line,"%d",&storage_.guild_id) == 1 && |
---|
274 | storage_.guild_id > 0 && |
---|
275 | guild_storage_fromstr(line,&storage_) == 0 |
---|
276 | ) { |
---|
277 | count++; |
---|
278 | guild_storage_tosql(storage_.guild_id, &storage_); |
---|
279 | } else |
---|
280 | ShowError("Error parsing guild storage line [%s] (at %s:%d)\n", line, guild_storage_txt, lineno); |
---|
281 | } |
---|
282 | ShowStatus("Converted %d guild storages.\n", count); |
---|
283 | fclose(fp); |
---|
284 | } |
---|
285 | |
---|
286 | //FIXME: CONVERT MAPREG HERE! (after enforcing MAPREGSQL for sql) |
---|
287 | |
---|
288 | return 0; |
---|
289 | } |
---|
290 | |
---|
291 | int do_init(int argc, char** argv) |
---|
292 | { |
---|
293 | char_config_read( (argc > 1) ? argv[1] : CHAR_CONF_NAME); |
---|
294 | mapindex_init(); |
---|
295 | sql_config_read( (argc > 2) ? argv[2] : SQL_CONF_NAME); |
---|
296 | inter_init_txt( (argc > 3) ? argv[3] : INTER_CONF_NAME); |
---|
297 | inter_init_sql( (argc > 3) ? argv[3] : INTER_CONF_NAME); |
---|
298 | convert_init(); |
---|
299 | ShowStatus("Everything's been converted!\n"); |
---|
300 | mapindex_final(); |
---|
301 | return 0; |
---|
302 | } |
---|
303 | |
---|
304 | void do_final(void) {} |
---|