root/src/ladmin/ladmin.c @ 10

Revision 1, 179.2 kB (checked in by jinshiro, 17 years ago)
Line 
1// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
2// For more information, see LICENCE in the main folder
3
4///////////////////////////////////////////////////////////////////////////
5// EAthena login-server remote administration tool
6// Ladamin in C by [Yor]
7// if you modify this software, modify ladmin in tool too.
8///////////////////////////////////////////////////////////////////////////
9
10#include "../common/cbasetypes.h"
11#include "../common/core.h"
12#include "../common/strlib.h"
13#include "../common/socket.h"
14#include "../common/timer.h"
15#include "../common/version.h"
16#include "../common/mmo.h"
17#include "../common/md5calc.h"
18#include "../common/showmsg.h"
19#include "ladmin.h"
20
21#include <sys/types.h>
22#include <time.h>
23#ifdef WIN32
24#define WIN32_LEAN_AND_MEAN
25#include <winsock2.h>
26void Gettimeofday(struct timeval *timenow)
27{
28        time_t t;
29        t = clock();
30        timenow->tv_usec = t;
31        timenow->tv_sec = t / CLK_TCK;
32        return;
33}
34#define gettimeofday(timenow, dummy) Gettimeofday(timenow)
35#else
36#include <sys/socket.h>
37#include <netinet/in.h>
38#include <sys/time.h> // gettimeofday
39#include <sys/ioctl.h>
40#include <unistd.h> // close
41#include <arpa/inet.h> // inet_addr
42#include <netdb.h> // gethostbyname
43#endif
44#include <stdio.h>
45#include <stdlib.h>
46#include <signal.h>
47#include <fcntl.h>
48#include <string.h> // str*
49#include <stdarg.h> // valist
50
51
52//-------------------------------INSTRUCTIONS------------------------------
53// Set the variables below:
54//   IP of the login server.
55//   Port where the login-server listens incoming packets.
56//   Password of administration (same of config_athena.conf).
57//   Displayed language of the sofware (if not correct, english is used).
58// IMPORTANT:
59//   Be sure that you authorize remote administration in login-server
60//   (see login_athena.conf, 'admin_state' parameter)
61//-------------------------------------------------------------------------
62char loginserverip[16] = "127.0.0.1";        // IP of login-server
63int loginserverport = 6900;                  // Port of login-server
64char loginserveradminpassword[24] = "admin"; // Administration password
65int passenc = 0;                             // Encoding type of the password
66char defaultlanguage = 'E';                  // Default language (F: Français/E: English)
67                                             // (if it's not 'F', default is English)
68char ladmin_log_filename[1024] = "log/ladmin.log";
69char date_format[32] = "%Y-%m-%d %H:%M:%S";
70//-------------------------------------------------------------------------
71//  LIST of COMMANDs that you can type at the prompt:
72//    To use these commands you can only type only the first letters.
73//    You must type a minimum of letters (you can not type 'a',
74//      because ladmin doesn't know if it's for 'aide' or for 'add')
75//    <Example> q <= quit, li <= list, pass <= passwd, etc.
76//
77//  Note: every time you must give a account_name, you can use "" or '' (spaces can be included)
78//
79//  aide/help/?
80//    Display the description of the commands
81//  aide/help/? [command]
82//    Display the description of the specified command
83//
84//  add <account_name> <sex> <password>
85//    Create an account with the default email (a@a.com).
86//    Concerning the sex, only the first letter is used (F or M).
87//    The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.
88//    When the password is omitted, the input is done without displaying of the pressed keys.
89//    <example> add testname Male testpass
90//
91//  ban/banish yyyy/mm/dd hh:mm:ss <account name>
92//    Changes the final date of a banishment of an account.
93//    Like banset, but <account name> is at end.
94//
95//  banadd <account_name> <modifier>
96//    Adds or substracts time from the final date of a banishment of an account.
97//    Modifier is done as follows:
98//      Adjustment value (-1, 1, +1, etc...)
99//      Modified element:
100//        a or y: year
101//        m:  month
102//        j or d: day
103//        h:  hour
104//        mn: minute
105//        s:  second
106//    <example> banadd testname +1m-2mn1s-6y
107//              this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
108//  NOTE: If you modify the final date of a non-banished account,
109//        you fix the final date to (actual time +- adjustments)
110//
111//  banset <account_name> yyyy/mm/dd [hh:mm:ss]
112//    Changes the final date of a banishment of an account.
113//    Default time [hh:mm:ss]: 23:59:59.
114//  banset <account_name> 0
115//    Set a non-banished account (0 = unbanished).
116//
117//  block <account name>
118//    Set state 5 (You have been blocked by the GM Team) to an account.
119//    Like state <account name> 5.
120//
121//  check <account_name> <password>
122//    Check the validity of a password for an account
123//    NOTE: Server will never send back a password.
124//          It's the only method you have to know if a password is correct.
125//          The other method is to have a ('physical') access to the accounts file.
126//
127//  create <account_name> <sex> <email> <password>
128//    Like the 'add' command, but with e-mail moreover.
129//    <example> create testname Male my@mail.com testpass
130//
131//  del <account name>
132//    Remove an account.
133//    This order requires confirmation. After confirmation, the account is deleted.
134//
135//  email <account_name> <email>
136//    Modify the e-mail of an account.
137//
138//  getcount
139//    Give the number of players online on all char-servers.
140//
141//  gm <account_name> [GM_level]
142//    Modify the GM level of an account.
143//    Default value remove GM level (GM level = 0).
144//    <example> gm testname 80
145//
146//  id <account name>
147//    Give the id of an account.
148//
149//  info <account_id>
150//    Display complete information of an account.
151//
152//  kami <message>
153//    Sends a broadcast message on all map-server (in yellow).
154//  kamib <message>
155//    Sends a broadcast message on all map-server (in blue).
156//
157//  language <language>
158//    Change the language of displaying.
159//
160//  list/ls [start_id [end_id]]
161//    Display a list of accounts.
162//    'start_id', 'end_id': indicate end and start identifiers.
163//    Research by name is not possible with this command.
164//    <example> list 10 9999999
165//
166//  listBan/lsBan [start_id [end_id]]
167//    Like list/ls, but only for accounts with state or banished
168//
169//  listGM/lsGM [start_id [end_id]]
170//    Like list/ls, but only for GM accounts
171//
172//  listOK/lsOK [start_id [end_id]]
173//    Like list/ls, but only for accounts without state and not banished
174//
175//  memo <account_name> <memo>
176//    Modify the memo of an account.
177//    'memo': it can have until 253 characters (with spaces or not).
178//
179//  name <account_id>
180//    Give the name of an account.
181//
182//  passwd <account_name> <new_password>
183//    Change the password of an account.
184//    When new password is omitted, the input is done without displaying of the pressed keys.
185//
186//  quit/end/exit
187//    End of the program of administration
188//
189//  reloadGM
190//    Reload GM configuration file
191//
192//  search <expression>
193//    Seek accounts.
194//    Displays the accounts whose names correspond.
195//  search -r/-e/--expr/--regex <expression>
196//    Seek accounts by regular expression.
197//    Displays the accounts whose names correspond.
198//
199//  sex <account_name> <sex>
200//    Modify the sex of an account.
201//    <example> sex testname Male
202//
203//  state <account_name> <new_state> <error_message_#7>
204//    Change the state of an account.
205//    'new_state': state is the state of the packet 0x006a + 1. The possibilities are:
206//                 0 = Account ok            6 = Your Game's EXE file is not the latest version
207//                 1 = Unregistered ID       7 = You are Prohibited to log in until %s
208//                 2 = Incorrect Password    8 = Server is jammed due to over populated
209//                 3 = This ID is expired    9 = No MSG
210//                 4 = Rejected from Server  100 = This ID has been totally erased
211//                 5 = You have been blocked by the GM Team
212//                 all other values are 'No MSG', then use state 9 please.
213//    'error_message_#7': message of the code error 6 = Your are Prohibited to log in until %s (packet 0x006a)
214//
215//  timeadd <account_name> <modifier>
216//    Adds or substracts time from the validity limit of an account.
217//    Modifier is done as follows:
218//      Adjustment value (-1, 1, +1, etc...)
219//      Modified element:
220//        a or y: year
221//        m:  month
222//        j or d: day
223//        h:  hour
224//        mn: minute
225//        s:  second
226//    <example> timeadd testname +1m-2mn1s-6y
227//              this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
228//  NOTE: You can not modify a unlimited validity limit.
229//        If you want modify it, you want probably create a limited validity limit.
230//        So, at first, you must set the validity limit to a date/time.
231//
232//  timeset <account_name> yyyy/mm/dd [hh:mm:ss]
233//    Changes the validity limit of an account.
234//    Default time [hh:mm:ss]: 23:59:59.
235//  timeset <account_name> 0
236//    Gives an unlimited validity limit (0 = unlimited).
237//
238//  unban/unbanish <account name>
239//    Unban an account.
240//    Like banset <account name> 0.
241//
242//  unblock <account name>
243//    Set state 0 (Account ok) to an account.
244//    Like state <account name> 0.
245//
246//  version
247//    Display the version of the login-server.
248//
249//  who <account name>
250//    Displays complete information of an account.
251//
252//-------------------------------------------------------------------------
253int login_fd;
254int login_ip;
255int bytes_to_read = 0; // flag to know if we waiting bytes from login-server
256char command[1024];
257char parameters[1024];
258int list_first, list_last, list_type, list_count; // parameter to display a list of accounts
259int already_exit_function = 0; // sometimes, the exit function is called twice... so, don't log twice the message
260
261//------------------------------
262// Writing function of logs file
263//------------------------------
264int ladmin_log(char *fmt, ...)
265{
266        FILE *logfp;
267        va_list ap;
268        struct timeval tv;
269        char tmpstr[2048];
270
271        va_start(ap, fmt);
272
273        logfp = fopen(ladmin_log_filename, "a");
274        if (logfp) {
275                if (fmt[0] == '\0') // jump a line if no message
276                        fprintf(logfp, "\n");
277                else {
278                        gettimeofday(&tv, NULL);
279                        strftime(tmpstr, 24, date_format, localtime((const time_t*)&(tv.tv_sec)));
280                        sprintf(tmpstr + strlen(tmpstr), ".%03d: %s", (int)tv.tv_usec / 1000, fmt);
281                        vfprintf(logfp, tmpstr, ap);
282                }
283                fclose(logfp);
284        }
285
286        va_end(ap);
287        return 0;
288}
289
290//---------------------------------------------
291// Function to return ordonal text of a number.
292//---------------------------------------------
293char* makeordinal(int number)
294{
295        if (defaultlanguage == 'F') {
296                if (number == 0)
297                        return "";
298                else if (number == 1)
299                        return "er";
300                else
301                        return "ème";
302        } else {
303                if ((number % 10) < 4 && (number % 10) != 0 && (number < 10 || number > 20)) {
304                        if ((number % 10) == 1)
305                                return "st";
306                        else if ((number % 10) == 2)
307                                return "nd";
308                        else
309                                return "rd";
310                } else {
311                        return "th";
312                }
313        }
314        return "";
315}
316
317//-----------------------------------------------------------------------------------------
318// Function to test of the validity of an account name (return 0 if incorrect, and 1 if ok)
319//-----------------------------------------------------------------------------------------
320int verify_accountname(char* account_name)
321{
322        int i;
323
324        for(i = 0; account_name[i]; i++) {
325                if (account_name[i] < 32) {
326                        if (defaultlanguage == 'F') {
327                                ShowMessage("Caractère interdit trouvé dans le nom du compte (%d%s caractère).\n", i+1, makeordinal(i+1));
328                                ladmin_log("Caractère interdit trouvé dans le nom du compte (%d%s caractère).\n", i+1, makeordinal(i+1));
329                        } else {
330                                ShowMessage("Illegal character found in the account name (%d%s character).\n", i+1, makeordinal(i+1));
331                                ladmin_log("Illegal character found in the account name (%d%s character).\n", i+1, makeordinal(i+1));
332                        }
333                        return 0;
334                }
335        }
336
337        if (strlen(account_name) < 4) {
338                if (defaultlanguage == 'F') {
339                        ShowMessage("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères.\n");
340                        ladmin_log("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères.\n");
341                } else {
342                        ShowMessage("Account name is too short. Please input an account name of 4-23 bytes.\n");
343                        ladmin_log("Account name is too short. Please input an account name of 4-23 bytes.\n");
344                }
345                return 0;
346        }
347
348        if (strlen(account_name) > 23) {
349                if (defaultlanguage == 'F') {
350                        ShowMessage("Nom du compte trop long. Entrez un nom de compte de 4-23 caractères.\n");
351                        ladmin_log("Nom du compte trop long. Entrez un nom de compte de 4-23 caractères.\n");
352                } else {
353                        ShowMessage("Account name is too long. Please input an account name of 4-23 bytes.\n");
354                        ladmin_log("Account name is too long. Please input an account name of 4-23 bytes.\n");
355                }
356                return 0;
357        }
358
359        return 1;
360}
361
362//----------------------------------
363// Sub-function: Input of a password
364//----------------------------------
365int typepasswd(char * password)
366{
367        char password1[1023], password2[1023];
368        int letter;
369        int i;
370
371        if (defaultlanguage == 'F') {
372                ladmin_log("Aucun mot de passe n'a été donné. Demande d'un mot de passe.\n");
373        } else {
374                ladmin_log("No password was given. Request to obtain a password.\n");
375        }
376
377        memset(password1, '\0', sizeof(password1));
378        memset(password2, '\0', sizeof(password2));
379        if (defaultlanguage == 'F')
380                ShowMessage("\033[1;36m Entrez le mot de passe > \033[0;32;42m");
381        else
382                ShowMessage("\033[1;36m Type the password > \033[0;32;42m");
383                i = 0;
384                while ((letter = getchar()) != '\n')
385                        password1[i++] = letter;
386        if (defaultlanguage == 'F')
387                ShowMessage("\033[0m\033[1;36m Ré-entrez le mot de passe > \033[0;32;42m");
388        else
389                ShowMessage("\033[0m\033[1;36m Verify the password > \033[0;32;42m");
390                i = 0;
391                while ((letter = getchar()) != '\n')
392                        password2[i++] = letter;
393
394        ShowMessage("\033[0m");
395        fflush(stdout);
396        fflush(stdin);
397
398        if (strcmp(password1, password2) != 0) {
399                if (defaultlanguage == 'F') {
400                        ShowMessage("Erreur de vérification du mot de passe: Saisissez le même mot de passe svp.\n");
401                        ladmin_log("Erreur de vérification du mot de passe: Saisissez le même mot de passe svp.\n");
402                        ladmin_log("  Premier mot de passe: %s, second mot de passe: %s.\n", password1, password2);
403                } else {
404                        ShowMessage("Password verification failed. Please input same password.\n");
405                        ladmin_log("Password verification failed. Please input same password.\n");
406                        ladmin_log("  First password: %s, second password: %s.\n", password1, password2);
407                }
408                return 0;
409        }
410        if (defaultlanguage == 'F') {
411                ladmin_log("Mot de passe saisi: %s.\n", password1);
412        } else {
413                ladmin_log("Typed password: %s.\n", password1);
414        }
415        strcpy(password, password1);
416        return 1;
417}
418
419//------------------------------------------------------------------------------------
420// Sub-function: Test of the validity of password (return 0 if incorrect, and 1 if ok)
421//------------------------------------------------------------------------------------
422int verify_password(char * password)
423{
424        int i;
425
426        for(i = 0; password[i]; i++) {
427                if (password[i] < 32) {
428                        if (defaultlanguage == 'F') {
429                                ShowMessage("Caractère interdit trouvé dans le mot de passe (%d%s caractère).\n", i+1, makeordinal(i+1));
430                                ladmin_log("Caractère interdit trouvé dans le nom du compte (%d%s caractère).\n", i+1, makeordinal(i+1));
431                        } else {
432                                ShowMessage("Illegal character found in the password (%d%s character).\n", i+1, makeordinal(i+1));
433                                ladmin_log("Illegal character found in the password (%d%s character).\n", i+1, makeordinal(i+1));
434                        }
435                        return 0;
436                }
437        }
438
439        if (strlen(password) < 4) {
440                if (defaultlanguage == 'F') {
441                        ShowMessage("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères.\n");
442                        ladmin_log("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères.\n");
443                } else {
444                        ShowMessage("Account name is too short. Please input an account name of 4-23 bytes.\n");
445                        ladmin_log("Account name is too short. Please input an account name of 4-23 bytes.\n");
446                }
447                return 0;
448        }
449
450        if (strlen(password) > 23) {
451                if (defaultlanguage == 'F') {
452                        ShowMessage("Mot de passe trop long. Entrez un mot de passe de 4-23 caractères.\n");
453                        ladmin_log("Mot de passe trop long. Entrez un mot de passe de 4-23 caractères.\n");
454                } else {
455                        ShowMessage("Password is too long. Please input a password of 4-23 bytes.\n");
456                        ladmin_log("Password is too long. Please input a password of 4-23 bytes.\n");
457                }
458                return 0;
459        }
460
461        return 1;
462}
463
464//------------------------------------------------------------------
465// Sub-function: Check the name of a command (return complete name)
466//-----------------------------------------------------------------
467int check_command(char * command)
468{
469// help
470        if (strncmp(command, "aide", 2) == 0 && strncmp(command, "aide", strlen(command)) == 0) // not 1 letter command: 'aide' or 'add'?
471                strcpy(command, "aide");
472        else if (strncmp(command, "help", 1) == 0 && strncmp(command, "help", strlen(command)) == 0)
473                strcpy(command, "help");
474// general commands
475        else if (strncmp(command, "add", 2) == 0 && strncmp(command, "add", strlen(command)) == 0) // not 1 letter command: 'aide' or 'add'?
476                strcpy(command, "add");
477        else if ((strncmp(command, "ban", 3) == 0 && strncmp(command, "ban", strlen(command)) == 0) ||
478                 (strncmp(command, "banish", 4) == 0 && strncmp(command, "banish", strlen(command)) == 0))
479                strcpy(command, "ban");
480        else if ((strncmp(command, "banadd", 4) == 0 && strncmp(command, "banadd", strlen(command)) == 0) || // not 1 letter command: 'ba' or 'bs'? 'banadd' or 'banset' ?
481                 strcmp(command,   "ba") == 0)
482                strcpy(command, "banadd");
483        else if ((strncmp(command, "banset", 4) == 0 && strncmp(command, "banset", strlen(command)) == 0) || // not 1 letter command: 'ba' or 'bs'? 'banadd' or 'banset' ?
484                 strcmp(command,   "bs") == 0)
485                strcpy(command, "banset");
486        else if (strncmp(command, "block", 2) == 0 && strncmp(command, "block", strlen(command)) == 0)
487                strcpy(command, "block");
488        else if (strncmp(command, "check", 2) == 0 && strncmp(command, "check", strlen(command)) == 0) // not 1 letter command: 'check' or 'create'?
489                strcpy(command, "check");
490        else if (strncmp(command, "create", 2) == 0 && strncmp(command, "create", strlen(command)) == 0) // not 1 letter command: 'check' or 'create'?
491                strcpy(command, "create");
492        else if (strncmp(command, "delete", 1) == 0 && strncmp(command, "delete", strlen(command)) == 0)
493                strcpy(command, "delete");
494        else if ((strncmp(command, "email", 2) == 0 && strncmp(command, "email", strlen(command)) == 0) || // not 1 letter command: 'email', 'end' or 'exit'?
495                 (strncmp(command, "e-mail", 2) == 0 && strncmp(command, "e-mail", strlen(command)) == 0))
496                strcpy(command, "email");
497        else if (strncmp(command, "getcount", 2) == 0 && strncmp(command, "getcount", strlen(command)) == 0) // not 1 letter command: 'getcount' or 'gm'?
498                strcpy(command, "getcount");
499//      else if (strncmp(command, "gm", 2) == 0 && strncmp(command, "gm", strlen(command)) == 0) // not 1 letter command: 'getcount' or 'gm'?
500//              strcpy(command, "gm");
501//      else if (strncmp(command, "id", 2) == 0 && strncmp(command, "id", strlen(command)) == 0) // not 1 letter command: 'id' or 'info'?
502//              strcpy(command, "id");
503        else if (strncmp(command, "info", 2) == 0 && strncmp(command, "info", strlen(command)) == 0) // not 1 letter command: 'id' or 'info'?
504                strcpy(command, "info");
505//      else if (strncmp(command, "kami", 4) == 0 && strncmp(command, "kami", strlen(command)) == 0) // only all letters command: 'kami' or 'kamib'?
506//              strcpy(command, "kami");
507//      else if (strncmp(command, "kamib", 5) == 0 && strncmp(command, "kamib", strlen(command)) == 0) // only all letters command: 'kami' or 'kamib'?
508//              strcpy(command, "kamib");
509        else if ((strncmp(command, "language", 2) == 0 && strncmp(command, "language", strlen(command)) == 0)) // not 1 letter command: 'language' or 'list'?
510                strcpy(command, "language");
511        else if ((strncmp(command, "list", 2) == 0 && strncmp(command, "list", strlen(command)) == 0) || // 'list' is default list command // not 1 letter command: 'language' or 'list'?
512                 strcmp(command,   "ls") == 0)
513                strcpy(command, "list");
514        else if ((strncmp(command, "listban", 5) == 0 && strncmp(command, "listban", strlen(command)) == 0) ||
515                 (strncmp(command, "lsban", 3) == 0 && strncmp(command, "lsban", strlen(command)) == 0) ||
516                 strcmp(command, "lb") == 0)
517                strcpy(command, "listban");
518        else if ((strncmp(command, "listgm", 5) == 0 && strncmp(command, "listgm", strlen(command)) == 0) ||
519                 (strncmp(command, "lsgm", 3) == 0 && strncmp(command, "lsgm", strlen(command)) == 0) ||
520                 strcmp(command,  "lg") == 0)
521                strcpy(command, "listgm");
522        else if ((strncmp(command, "listok", 5) == 0 && strncmp(command, "listok", strlen(command)) == 0) ||
523                 (strncmp(command, "lsok", 3) == 0 && strncmp(command, "lsok", strlen(command)) == 0) ||
524                 strcmp(command, "lo") == 0)
525                strcpy(command, "listok");
526        else if (strncmp(command, "memo", 1) == 0 && strncmp(command, "memo", strlen(command)) == 0)
527                strcpy(command, "memo");
528        else if (strncmp(command, "name", 1) == 0 && strncmp(command, "name", strlen(command)) == 0)
529                strcpy(command, "name");
530        else if ((strncmp(command, "password", 1) == 0 && strncmp(command, "password", strlen(command)) == 0) ||
531                 strcmp(command, "passwd") == 0)
532                strcpy(command, "password");
533        else if (strncmp(command, "reloadgm", 1) == 0 && strncmp(command, "reloadgm", strlen(command)) == 0)
534                strcpy(command, "reloadgm");
535        else if (strncmp(command, "search", 3) == 0 && strncmp(command, "search", strlen(command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
536                strcpy(command, "search"); // not 2 letters command: 'search' or 'sex'?
537//      else if (strncmp(command, "sex", 3) == 0 && strncmp(command, "sex", strlen(command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
538//              strcpy(command, "sex"); // not 2 letters command: 'search' or 'sex'?
539        else if (strncmp(command, "state", 2) == 0 && strncmp(command, "state", strlen(command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
540                strcpy(command, "state");
541        else if ((strncmp(command, "timeadd", 5) == 0 && strncmp(command, "timeadd", strlen(command)) == 0) || // not 1 letter command: 'ta' or 'ts'? 'timeadd' or 'timeset'?
542                 strcmp(command,  "ta") == 0)
543                strcpy(command, "timeadd");
544        else if ((strncmp(command, "timeset", 5) == 0 && strncmp(command, "timeset", strlen(command)) == 0) || // not 1 letter command: 'ta' or 'ts'? 'timeadd' or 'timeset'?
545                 strcmp(command,  "ts") == 0)
546                strcpy(command, "timeset");
547        else if ((strncmp(command, "unban", 5) == 0 && strncmp(command, "unban", strlen(command)) == 0) ||
548                 (strncmp(command, "unbanish", 4) == 0 && strncmp(command, "unbanish", strlen(command)) == 0))
549                strcpy(command, "unban");
550        else if (strncmp(command, "unblock", 4) == 0 && strncmp(command, "unblock", strlen(command)) == 0)
551                strcpy(command, "unblock");
552        else if (strncmp(command, "version", 1) == 0 && strncmp(command, "version", strlen(command)) == 0)
553                strcpy(command, "version");
554        else if (strncmp(command, "who", 1) == 0 && strncmp(command, "who", strlen(command)) == 0)
555                strcpy(command, "who");
556// quit
557        else if (strncmp(command, "quit", 1) == 0 && strncmp(command, "quit", strlen(command)) == 0)
558                strcpy(command, "quit");
559        else if (strncmp(command, "exit", 2) == 0 && strncmp(command, "exit", strlen(command)) == 0) // not 1 letter command: 'email', 'end' or 'exit'?
560                strcpy(command, "exit");
561        else if (strncmp(command, "end", 2) == 0 && strncmp(command, "end", strlen(command)) == 0) // not 1 letter command: 'email', 'end' or 'exit'?
562                strcpy(command, "end");
563
564        return 0;
565}
566
567//-----------------------------------------
568// Sub-function: Display commands of ladmin
569//-----------------------------------------
570void display_help(char* param, int language)
571{
572        char command[1023];
573        int i;
574
575        memset(command, '\0', sizeof(command));
576
577        if (sscanf(param, "%s ", command) < 1 || strlen(command) == 0)
578                strcpy(command, ""); // any value that is not a command
579
580        if (command[0] == '?') {
581                if (defaultlanguage == 'F')
582                        strcpy(command, "aide");
583                else
584                        strcpy(command, "help");
585        }
586
587        // lowercase for command
588        for (i = 0; command[i]; i++)
589                command[i] = TOLOWER(command[i]);
590
591        // Analyse of the command
592        check_command(command); // give complete name to the command
593
594        if (defaultlanguage == 'F') {
595                ladmin_log("Affichage des commandes ou d'une commande.\n");
596        } else {
597                ladmin_log("Displaying of the commands or a command.\n");
598        }
599
600        if (language == 1) {
601                if (strcmp(command, "aide") == 0) {
602                        ShowMessage("aide/help/?\n");
603                        ShowMessage("  Affiche la description des commandes\n");
604                        ShowMessage("aide/help/? [commande]\n");
605                        ShowMessage("  Affiche la description de la commande specifiée\n");
606                } else if (strcmp(command, "help") == 0 ) {
607                        ShowMessage("aide/help/?\n");
608                        ShowMessage("  Display the description of the commands\n");
609                        ShowMessage("aide/help/? [command]\n");
610                        ShowMessage("  Display the description of the specified command\n");
611// general commands
612                } else if (strcmp(command, "add") == 0) {
613                        ShowMessage("add <nomcompte> <sexe> <motdepasse>\n");
614                        ShowMessage("  Crée un compte avec l'email par défaut (a@a.com).\n");
615                        ShowMessage("  Concernant le sexe, seule la première lettre compte (F ou M).\n");
616                        ShowMessage("  L'e-mail est a@a.com (e-mail par défaut). C'est comme n'avoir aucun e-mail.\n");
617                        ShowMessage("  Lorsque motdepasse est omis, la saisie se fait sans que la frappe se voit.\n");
618                        ShowMessage("  <exemple> add testname Male testpass\n");
619                } else if (strcmp(command, "ban") == 0) {
620                        ShowMessage("ban/banish aaaa/mm/jj hh:mm:ss <nom compte>\n");
621                        ShowMessage("  Change la date de fin de bannissement d'un compte.\n");
622                        ShowMessage("  Comme banset, mais <nom compte> est à la fin.\n");
623                } else if (strcmp(command, "banadd") == 0) {
624                        ShowMessage("banadd <nomcompte> <Modificateur>\n");
625                        ShowMessage("  Ajoute ou soustrait du temps à la date de banissement d'un compte.\n");
626                        ShowMessage("  Les modificateurs sont construits comme suit:\n");
627                        ShowMessage("    Valeur d'ajustement (-1, 1, +1, etc...)\n");
628                        ShowMessage("    Elément modifié:\n");
629                        ShowMessage("      a ou y: année\n");
630                        ShowMessage("      m:      mois\n");
631                        ShowMessage("      j ou d: jour\n");
632                        ShowMessage("      h:      heure\n");
633                        ShowMessage("      mn:     minute\n");
634                        ShowMessage("      s:      seconde\n");
635                        ShowMessage("  <exemple> banadd testname +1m-2mn1s-6a\n");
636                        ShowMessage("            Cette exemple ajoute 1 mois et une seconde, et soustrait 2 minutes\n");
637                        ShowMessage("            et 6 ans dans le même temps.\n");
638                        ShowMessage("NOTE: Si vous modifez la date de banissement d'un compte non bani,\n");
639                        ShowMessage("      vous indiquez comme date (le moment actuel +- les ajustements)\n");
640                } else if (strcmp(command, "banset") == 0) {
641                        ShowMessage("banset <nomcompte> aaaa/mm/jj [hh:mm:ss]\n");
642                        ShowMessage("  Change la date de fin de bannissement d'un compte.\n");
643                        ShowMessage("  Heure par défaut [hh:mm:ss]: 23:59:59.\n");
644                        ShowMessage("banset <nomcompte> 0\n");
645                        ShowMessage("  Débanni un compte (0 = de-banni).\n");
646                } else if (strcmp(command, "block") == 0) {
647                        ShowMessage("block <nom compte>\n");
648                        ShowMessage("  Place le status d'un compte à 5 (You have been blocked by the GM Team).\n");
649                        ShowMessage("  La commande est l'équivalent de state <nom_compte> 5.\n");
650                } else if (strcmp(command, "check") == 0) {
651                        ShowMessage("check <nomcompte> <motdepasse>\n");
652                        ShowMessage("  Vérifie la validité d'un mot de passe pour un compte\n");
653                        ShowMessage("  NOTE: Le serveur n'enverra jamais un mot de passe.\n");
654                        ShowMessage("        C'est la seule méthode que vous possédez pour savoir\n");
655                        ShowMessage("        si un mot de passe est le bon. L'autre méthode est\n");
656                        ShowMessage("        d'avoir un accès ('physique') au fichier des comptes.\n");
657                } else if (strcmp(command, "create") == 0) {
658                        ShowMessage("create <nomcompte> <sexe> <email> <motdepasse>\n");
659                        ShowMessage("  Comme la commande add, mais avec l'e-mail en plus.\n");
660                        ShowMessage("  <exemple> create testname Male mon@mail.com testpass\n");
661                } else if (strcmp(command, "delete") == 0) {
662                        ShowMessage("del <nom compte>\n");
663                        ShowMessage("  Supprime un compte.\n");
664                        ShowMessage("  La commande demande confirmation. Après confirmation, le compte est détruit.\n");
665                } else if (strcmp(command, "email") == 0) {
666                        ShowMessage("email <nomcompte> <email>\n");
667                        ShowMessage("  Modifie l'e-mail d'un compte.\n");
668                } else if (strcmp(command, "getcount") == 0) {
669                        ShowMessage("getcount\n");
670                        ShowMessage("  Donne le nombre de joueurs en ligne par serveur de char.\n");
671                } else if (strcmp(command, "gm") == 0) {
672                        ShowMessage("gm <nomcompte> [Niveau_GM]\n");
673                        ShowMessage("  Modifie le niveau de GM d'un compte.\n");
674                        ShowMessage("  Valeur par défaut: 0 (suppression du niveau de GM).\n");
675                        ShowMessage("  <exemple> gm nomtest 80\n");
676                } else if (strcmp(command, "id") == 0) {
677                        ShowMessage("id <nom compte>\n");
678                        ShowMessage("  Donne l'id d'un compte.\n");
679                } else if (strcmp(command, "info") == 0) {
680                        ShowMessage("info <idcompte>\n");
681                        ShowMessage("  Affiche les informations sur un compte.\n");
682                } else if (strcmp(command, "kami") == 0) {
683                        ShowMessage("kami <message>\n");
684                        ShowMessage("  Envoi un message général sur tous les serveurs de map (en jaune).\n");
685                } else if (strcmp(command, "kamib") == 0) {
686                        ShowMessage("kamib <message>\n");
687                        ShowMessage("  Envoi un message général sur tous les serveurs de map (en bleu).\n");
688                } else if (strcmp(command, "language") == 0) {
689                        ShowMessage("language <langue>\n");
690                        ShowMessage("  Change la langue d'affichage.\n");
691                        ShowMessage("  Langues possibles: 'Français' ou 'English'.\n");
692                } else if (strcmp(command, "list") == 0) {
693                        ShowMessage("list/ls [Premier_id [Dernier_id]]\n");
694                        ShowMessage("  Affiche une liste de comptes.\n");
695                        ShowMessage("  'Premier_id', 'Dernier_id': indique les identifiants de départ et de fin.\n");
696                        ShowMessage("  La recherche par nom n'est pas possible avec cette commande.\n");
697                        ShowMessage("  <example> list 10 9999999\n");
698                } else if (strcmp(command, "listban") == 0) {
699                        ShowMessage("listBan/lsBan [Premier_id [Dernier_id]]\n");
700                        ShowMessage("  Comme list/ls, mais seulement pour les comptes avec statut ou bannis.\n");
701                } else if (strcmp(command, "listgm") == 0) {
702                        ShowMessage("listGM/lsGM [Premier_id [Dernier_id]]\n");
703                        ShowMessage("  Comme list/ls, mais seulement pour les comptes GM.\n");
704                } else if (strcmp(command, "listok") == 0) {
705                        ShowMessage("listOK/lsOK [Premier_id [Dernier_id]]\n");
706                        ShowMessage("  Comme list/ls, mais seulement pour les comptes sans statut et non bannis.\n");
707                } else if (strcmp(command, "memo") == 0) {
708                        ShowMessage("memo <nomcompte> <memo>\n");
709                        ShowMessage("  Modifie le mémo d'un compte.\n");
710                        ShowMessage("  'memo': Il peut avoir jusqu'à 253 caractères (avec des espaces ou non).\n");
711                } else if (strcmp(command, "name") == 0) {
712                        ShowMessage("name <idcompte>\n");
713                        ShowMessage("  Donne le nom d'un compte.\n");
714                } else if (strcmp(command, "password") == 0) {
715                        ShowMessage("passwd <nomcompte> <nouveaumotdepasse>\n");
716                        ShowMessage("  Change le mot de passe d'un compte.\n");
717                        ShowMessage("  Lorsque nouveaumotdepasse est omis,\n");
718                        ShowMessage("  la saisie se fait sans que la frappe ne se voit.\n");
719                } else if (strcmp(command, "reloadgm") == 0) {
720                        ShowMessage("reloadGM\n");
721                        ShowMessage("  Reload GM configuration file\n");
722                } else if (strcmp(command, "search") == 0) {
723                        ShowMessage("search <expression>\n");
724                        ShowMessage("  Cherche des comptes.\n");
725                        ShowMessage("  Affiche les comptes dont les noms correspondent.\n");
726//                      ShowMessage("search -r/-e/--expr/--regex <expression>\n");
727//                      ShowMessage("  Cherche des comptes par expression regulière.\n");
728//                      ShowMessage("  Affiche les comptes dont les noms correspondent.\n");
729                } else if (strcmp(command, "sex") == 0) {
730                        ShowMessage("sex <nomcompte> <sexe>\n");
731                        ShowMessage("  Modifie le sexe d'un compte.\n");
732                        ShowMessage("  <exemple> sex testname Male\n");
733                } else if (strcmp(command, "state") == 0) {
734                        ShowMessage("state <nomcompte> <nouveaustatut> <message_erreur_7>\n");
735                        ShowMessage("  Change le statut d'un compte.\n");
736                        ShowMessage("  'nouveaustatut': Le statut est le même que celui du packet 0x006a + 1.\n");
737                        ShowMessage("               les possibilités sont:\n");
738                        ShowMessage("               0 = Compte ok\n");
739                        ShowMessage("               1 = Unregistered ID\n");
740                        ShowMessage("               2 = Incorrect Password\n");
741                        ShowMessage("               3 = This ID is expired\n");
742                        ShowMessage("               4 = Rejected from Server\n");
743                        ShowMessage("               5 = You have been blocked by the GM Team\n");
744                        ShowMessage("               6 = Your Game's EXE file is not the latest version\n");
745                        ShowMessage("               7 = You are Prohibited to log in until...\n");
746                        ShowMessage("               8 = Server is jammed due to over populated\n");
747                        ShowMessage("               9 = No MSG\n");
748                        ShowMessage("               100 = This ID has been totally erased\n");
749                        ShowMessage("               all other values are 'No MSG', then use state 9 please.\n");
750                        ShowMessage("  'message_erreur_7': message du code erreur 6 =\n");
751                        ShowMessage("                      = Your are Prohibited to log in until... (packet 0x006a)\n");
752                } else if (strcmp(command, "timeadd") == 0) {
753                        ShowMessage("timeadd <nomcompte> <modificateur>\n");
754                        ShowMessage("  Ajoute/soustrait du temps à la limite de validité d'un compte.\n");
755                        ShowMessage("  Le modificateur est composé comme suit:\n");
756                        ShowMessage("    Valeur modificatrice (-1, 1, +1, etc...)\n");
757                        ShowMessage("    Elément modifié:\n");
758                        ShowMessage("      a ou y: année\n");
759                        ShowMessage("      m:      mois\n");
760                        ShowMessage("      j ou d: jour\n");
761                        ShowMessage("      h:      heure\n");
762                        ShowMessage("      mn:     minute\n");
763                        ShowMessage("      s:      seconde\n");
764                        ShowMessage("  <exemple> timeadd testname +1m-2mn1s-6a\n");
765                        ShowMessage("            Cette exemple ajoute 1 mois et une seconde, et soustrait 2 minutes\n");
766                        ShowMessage("            et 6 ans dans le même temps.\n");
767                        ShowMessage("NOTE: Vous ne pouvez pas modifier une limite de validité illimitée. Si vous\n");
768                        ShowMessage("      désirez le faire, c'est que vous voulez probablement créer un limite de\n");
769                        ShowMessage("      validité limitée. Donc, en premier, fixé une limite de valitidé.\n");
770                } else if (strcmp(command, "timeadd") == 0) {
771                        ShowMessage("timeset <nomcompte> aaaa/mm/jj [hh:mm:ss]\n");
772                        ShowMessage("  Change la limite de validité d'un compte.\n");
773                        ShowMessage("  Heure par défaut [hh:mm:ss]: 23:59:59.\n");
774                        ShowMessage("timeset <nomcompte> 0\n");
775                        ShowMessage("  Donne une limite de validité illimitée (0 = illimitée).\n");
776                } else if (strcmp(command, "unban") == 0) {
777                        ShowMessage("unban/unbanish <nom compte>\n");
778                        ShowMessage("  Ote le banissement d'un compte.\n");
779                        ShowMessage("  La commande est l'équivalent de banset <nom_compte> 0.\n");
780                } else if (strcmp(command, "unblock") == 0) {
781                        ShowMessage("unblock <nom compte>\n");
782                        ShowMessage("  Place le status d'un compte à 0 (Compte ok).\n");
783                        ShowMessage("  La commande est l'équivalent de state <nom_compte> 0.\n");
784                } else if (strcmp(command, "version") == 0) {
785                        ShowMessage("version\n");
786                        ShowMessage("  Affiche la version du login-serveur.\n");
787                } else if (strcmp(command, "who") == 0) {
788                        ShowMessage("who <nom compte>\n");
789                        ShowMessage("  Affiche les informations sur un compte.\n");
790// quit
791                } else if (strcmp(command, "quit") == 0 ||
792                           strcmp(command, "exit") == 0 ||
793                           strcmp(command, "end") == 0) {
794                        ShowMessage("quit/end/exit\n");
795                        ShowMessage("  Fin du programme d'administration.\n");
796// unknown command
797                } else {
798                        if (strlen(command) > 0)
799                                ShowMessage("Commande inconnue [%s] pour l'aide. Affichage de toutes les commandes.\n", command);
800                        ShowMessage(" aide/help/?                             -- Affiche cet aide\n");
801                        ShowMessage(" aide/help/? [commande]                  -- Affiche l'aide de la commande\n");
802                        ShowMessage(" add <nomcompte> <sexe> <motdepasse>     -- Crée un compte (sans email)\n");
803                        ShowMessage(" ban/banish aaaa/mm/jj hh:mm:ss <nom compte> -- Fixe la date finale de banismnt\n");
804                        ShowMessage(" banadd/ba <nomcompte> <modificateur>    -- Ajout/soustrait du temps à la\n");
805                        ShowMessage("   exemple: ba moncompte +1m-2mn1s-2y       date finale de banissement\n");
806                        ShowMessage(" banset/bs <nomcompte> aaaa/mm/jj [hh:mm:ss] -- Change la date fin de banisemnt\n");
807                        ShowMessage(" banset/bs <nomcompte> 0                 -- Dé-banis un compte.\n");
808                        ShowMessage(" block <nom compte>  -- Mets le status d'un compte à 5 (blocked by the GM Team)\n");
809                        ShowMessage(" check <nomcompte> <motdepasse>          -- Vérifie un mot de passe d'un compte\n");
810                        ShowMessage(" create <nomcompte> <sexe> <email> <motdepasse> -- Crée un compte (avec email)\n");
811                        ShowMessage(" del <nom compte>                        -- Supprime un compte\n");
812                        ShowMessage(" email <nomcompte> <email>               -- Modifie l'e-mail d'un compte\n");
813                        ShowMessage(" getcount                                -- Donne le nb de joueurs en ligne\n");
814                        ShowMessage("  gm <nomcompte> [Niveau_GM]              -- Modifie le niveau de GM d'un compte\n");
815                        ShowMessage(" id <nom compte>                         -- Donne l'id d'un compte\n");
816                        ShowMessage(" info <idcompte>                         -- Affiche les infos sur un compte\n");
817                        ShowMessage(" kami <message>                          -- Envoi un message général (en jaune)\n");
818                        ShowMessage(" kamib <message>                         -- Envoi un message général (en bleu)\n");
819                        ShowMessage(" language <langue>                       -- Change la langue d'affichage.\n");
820                        ShowMessage(" list/ls [Premier_id [Dernier_id] ]      -- Affiche une liste de comptes\n");
821                        ShowMessage(" listBan/lsBan [Premier_id [Dernier_id] ] -- Affiche une liste de comptes\n");
822                        ShowMessage("                                             avec un statut ou bannis\n");
823                        ShowMessage(" listGM/lsGM [Premier_id [Dernier_id] ]  -- Affiche une liste de comptes GM\n");
824                        ShowMessage(" listOK/lsOK [Premier_id [Dernier_id] ]  -- Affiche une liste de comptes\n");
825                        ShowMessage("                                            sans status et non bannis\n");
826                        ShowMessage(" memo <nomcompte> <memo>                 -- Modifie le memo d'un compte\n");
827                        ShowMessage(" name <idcompte>                         -- Donne le nom d'un compte\n");
828                        ShowMessage(" passwd <nomcompte> <nouveaumotdepasse>  -- Change le mot de passe d'un compte\n");
829                        ShowMessage(" quit/end/exit                           -- Fin du programme d'administation\n");
830                        ShowMessage(" reloadGM                              -- Recharger le fichier de config des GM\n");
831                        ShowMessage(" search <expression>                     -- Cherche des comptes\n");
832//                      ShowMessage(" search -e/-r/--expr/--regex <expression> -- Cherche des comptes par REGEX\n");
833                        ShowMessage(" sex <nomcompte> <sexe>                  -- Modifie le sexe d'un compte\n");
834                        ShowMessage(" state <nomcompte> <nouveaustatut> <messageerr7> -- Change le statut d'1 compte\n");
835                        ShowMessage(" timeadd/ta <nomcompte> <modificateur>   -- Ajout/soustrait du temps à la\n");
836                        ShowMessage("   exemple: ta moncompte +1m-2mn1s-2y       limite de validité\n");
837                        ShowMessage(" timeset/ts <nomcompte> aaaa/mm/jj [hh:mm:ss] -- Change la limite de validité\n");
838                        ShowMessage(" timeset/ts <nomcompte> 0                -- limite de validité = illimitée\n");
839                        ShowMessage(" unban/unbanish <nom compte>             -- Ote le banissement d'un compte\n");
840                        ShowMessage(" unblock <nom compte>             -- Mets le status d'un compte à 0 (Compte ok)\n");
841                        ShowMessage(" version                                 -- Donne la version du login-serveur\n");
842                        ShowMessage(" who <nom compte>                        -- Affiche les infos sur un compte\n");
843                        ShowMessage(" Note: Pour les noms de compte avec des espaces, tapez \"<nom compte>\" (ou ').\n");
844                }
845        } else {
846                if (strcmp(command, "aide") == 0) {
847                        ShowMessage("aide/help/?\n");
848                        ShowMessage("  Display the description of the commands\n");
849                        ShowMessage("aide/help/? [command]\n");
850                        ShowMessage("  Display the description of the specified command\n");
851                } else if (strcmp(command, "help") == 0 ) {
852                        ShowMessage("aide/help/?\n");
853                        ShowMessage("  Display the description of the commands\n");
854                        ShowMessage("aide/help/? [command]\n");
855                        ShowMessage("  Display the description of the specified command\n");
856// general commands
857                } else if (strcmp(command, "add") == 0) {
858                        ShowMessage("add <account_name> <sex> <password>\n");
859                        ShowMessage("  Create an account with the default email (a@a.com).\n");
860                        ShowMessage("  Concerning the sex, only the first letter is used (F or M).\n");
861                        ShowMessage("  The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n");
862                        ShowMessage("  When the password is omitted,\n");
863                        ShowMessage("  the input is done without displaying of the pressed keys.\n");
864                        ShowMessage("  <example> add testname Male testpass\n");
865                } else if (strcmp(command, "ban") == 0) {
866                        ShowMessage("ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
867                        ShowMessage("  Changes the final date of a banishment of an account.\n");
868                        ShowMessage("  Like banset, but <account name> is at end.\n");
869                } else if (strcmp(command, "banadd") == 0) {
870                        ShowMessage("banadd <account_name> <modifier>\n");
871                        ShowMessage("  Adds or substracts time from the final date of a banishment of an account.\n");
872                        ShowMessage("  Modifier is done as follows:\n");
873                        ShowMessage("    Adjustment value (-1, 1, +1, etc...)\n");
874                        ShowMessage("    Modified element:\n");
875                        ShowMessage("      a or y: year\n");
876                        ShowMessage("      m:  month\n");
877                        ShowMessage("      j or d: day\n");
878                        ShowMessage("      h:  hour\n");
879                        ShowMessage("      mn: minute\n");
880                        ShowMessage("      s:  second\n");
881                        ShowMessage("  <example> banadd testname +1m-2mn1s-6y\n");
882                        ShowMessage("            this example adds 1 month and 1 second, and substracts 2 minutes\n");
883                        ShowMessage("            and 6 years at the same time.\n");
884                        ShowMessage("NOTE: If you modify the final date of a non-banished account,\n");
885                        ShowMessage("      you fix the final date to (actual time +- adjustments)\n");
886                } else if (strcmp(command, "banset") == 0) {
887                        ShowMessage("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
888                        ShowMessage("  Changes the final date of a banishment of an account.\n");
889                        ShowMessage("  Default time [hh:mm:ss]: 23:59:59.\n");
890                        ShowMessage("banset <account_name> 0\n");
891                        ShowMessage("  Set a non-banished account (0 = unbanished).\n");
892                } else if (strcmp(command, "block") == 0) {
893                        ShowMessage("block <account name>\n");
894                        ShowMessage("  Set state 5 (You have been blocked by the GM Team) to an account.\n");
895                        ShowMessage("  This command works like state <account_name> 5.\n");
896                } else if (strcmp(command, "check") == 0) {
897                        ShowMessage("check <account_name> <password>\n");
898                        ShowMessage("  Check the validity of a password for an account.\n");
899                        ShowMessage("  NOTE: Server will never send back a password.\n");
900                        ShowMessage("        It's the only method you have to know if a password is correct.\n");
901                        ShowMessage("        The other method is to have a ('physical') access to the accounts file.\n");
902                } else if (strcmp(command, "create") == 0) {
903                        ShowMessage("create <account_name> <sex> <email> <password>\n");
904                        ShowMessage("  Like the 'add' command, but with e-mail moreover.\n");
905                        ShowMessage("  <example> create testname Male my@mail.com testpass\n");
906                } else if (strcmp(command, "delete") == 0) {
907                        ShowMessage("del <account name>\n");
908                        ShowMessage("  Remove an account.\n");
909                        ShowMessage("  This order requires confirmation. After confirmation, the account is deleted.\n");
910                } else if (strcmp(command, "email") == 0) {
911                        ShowMessage("email <account_name> <email>\n");
912                        ShowMessage("  Modify the e-mail of an account.\n");
913                } else if (strcmp(command, "getcount") == 0) {
914                        ShowMessage("getcount\n");
915                        ShowMessage("  Give the number of players online on all char-servers.\n");
916                } else if (strcmp(command, "gm") == 0) {
917                        ShowMessage("gm <account_name> [GM_level]\n");
918                        ShowMessage("  Modify the GM level of an account.\n");
919                        ShowMessage("  Default value remove GM level (GM level = 0).\n");
920                        ShowMessage("  <example> gm testname 80\n");
921                } else if (strcmp(command, "id") == 0) {
922                        ShowMessage("id <account name>\n");
923                        ShowMessage("  Give the id of an account.\n");
924                } else if (strcmp(command, "info") == 0) {
925                        ShowMessage("info <account_id>\n");
926                        ShowMessage("  Display complete information of an account.\n");
927                } else if (strcmp(command, "kami") == 0) {
928                        ShowMessage("kami <message>\n");
929                        ShowMessage("  Sends a broadcast message on all map-server (in yellow).\n");
930                } else if (strcmp(command, "kamib") == 0) {
931                        ShowMessage("kamib <message>\n");
932                        ShowMessage("  Sends a broadcast message on all map-server (in blue).\n");
933                } else if (strcmp(command, "language") == 0) {
934                        ShowMessage("language <language>\n");
935                        ShowMessage("  Change the language of displaying.\n");
936                        ShowMessage("  Possible languages: Français or English.\n");
937                } else if (strcmp(command, "list") == 0) {
938                        ShowMessage("list/ls [start_id [end_id]]\n");
939                        ShowMessage("  Display a list of accounts.\n");
940                        ShowMessage("  'start_id', 'end_id': indicate end and start identifiers.\n");
941                        ShowMessage("  Research by name is not possible with this command.\n");
942                        ShowMessage("  <example> list 10 9999999\n");
943                } else if (strcmp(command, "listban") == 0) {
944                        ShowMessage("listBan/lsBan [start_id [end_id]]\n");
945                        ShowMessage("  Like list/ls, but only for accounts with state or banished.\n");
946                } else if (strcmp(command, "listgm") == 0) {
947                        ShowMessage("listGM/lsGM [start_id [end_id]]\n");
948                        ShowMessage("  Like list/ls, but only for GM accounts.\n");
949                } else if (strcmp(command, "listok") == 0) {
950                        ShowMessage("listOK/lsOK [start_id [end_id]]\n");
951                        ShowMessage("  Like list/ls, but only for accounts without state and not banished.\n");
952                } else if (strcmp(command, "memo") == 0) {
953                        ShowMessage("memo <account_name> <memo>\n");
954                        ShowMessage("  Modify the memo of an account.\n");
955                        ShowMessage("  'memo': it can have until 253 characters (with spaces or not).\n");
956                } else if (strcmp(command, "name") == 0) {
957                        ShowMessage("name <account_id>\n");
958                        ShowMessage("  Give the name of an account.\n");
959                } else if (strcmp(command, "password") == 0) {
960                        ShowMessage("passwd <account_name> <new_password>\n");
961                        ShowMessage("  Change the password of an account.\n");
962                        ShowMessage("  When new password is omitted,\n");
963                        ShowMessage("  the input is done without displaying of the pressed keys.\n");
964                } else if (strcmp(command, "reloadgm") == 0) {
965                        ShowMessage("reloadGM\n");
966                        ShowMessage("  Reload GM configuration file\n");
967                } else if (strcmp(command, "search") == 0) {
968                        ShowMessage("search <expression>\n");
969                        ShowMessage("  Seek accounts.\n");
970                        ShowMessage("  Displays the accounts whose names correspond.\n");
971//                      ShowMessage("search -r/-e/--expr/--regex <expression>\n");
972//                      ShowMessage("  Seek accounts by regular expression.\n");
973//                      ShowMessage("  Displays the accounts whose names correspond.\n");
974                } else if (strcmp(command, "sex") == 0) {
975                        ShowMessage("sex <account_name> <sex>\n");
976                        ShowMessage("  Modify the sex of an account.\n");
977                        ShowMessage("  <example> sex testname Male\n");
978                } else if (strcmp(command, "state") == 0) {
979                        ShowMessage("state <account_name> <new_state> <error_message_#7>\n");
980                        ShowMessage("  Change the state of an account.\n");
981                        ShowMessage("  'new_state': state is the state of the packet 0x006a + 1.\n");
982                        ShowMessage("               The possibilities are:\n");
983                        ShowMessage("               0 = Account ok\n");
984                        ShowMessage("               1 = Unregistered ID\n");
985                        ShowMessage("               2 = Incorrect Password\n");
986                        ShowMessage("               3 = This ID is expired\n");
987                        ShowMessage("               4 = Rejected from Server\n");
988                        ShowMessage("               5 = You have been blocked by the GM Team\n");
989                        ShowMessage("               6 = Your Game's EXE file is not the latest version\n");
990                        ShowMessage("               7 = You are Prohibited to log in until...\n");
991                        ShowMessage("               8 = Server is jammed due to over populated\n");
992                        ShowMessage("               9 = No MSG\n");
993                        ShowMessage("               100 = This ID has been totally erased\n");
994                        ShowMessage("               all other values are 'No MSG', then use state 9 please.\n");
995                        ShowMessage("  'error_message_#7': message of the code error 6\n");
996                        ShowMessage("                      = Your are Prohibited to log in until... (packet 0x006a)\n");
997                } else if (strcmp(command, "timeadd") == 0) {
998                        ShowMessage("timeadd <account_name> <modifier>\n");
999                        ShowMessage("  Adds or substracts time from the validity limit of an account.\n");
1000                        ShowMessage("  Modifier is done as follows:\n");
1001                        ShowMessage("    Adjustment value (-1, 1, +1, etc...)\n");
1002                        ShowMessage("    Modified element:\n");
1003                        ShowMessage("      a or y: year\n");
1004                        ShowMessage("      m:  month\n");
1005                        ShowMessage("      j or d: day\n");
1006                        ShowMessage("      h:  hour\n");
1007                        ShowMessage("      mn: minute\n");
1008                        ShowMessage("      s:  second\n");
1009                        ShowMessage("  <example> timeadd testname +1m-2mn1s-6y\n");
1010                        ShowMessage("            this example adds 1 month and 1 second, and substracts 2 minutes\n");
1011                        ShowMessage("            and 6 years at the same time.\n");
1012                        ShowMessage("NOTE: You can not modify a unlimited validity limit.\n");
1013                        ShowMessage("      If you want modify it, you want probably create a limited validity limit.\n");
1014                        ShowMessage("      So, at first, you must set the validity limit to a date/time.\n");
1015                } else if (strcmp(command, "timeadd") == 0) {
1016                        ShowMessage("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
1017                        ShowMessage("  Changes the validity limit of an account.\n");
1018                        ShowMessage("  Default time [hh:mm:ss]: 23:59:59.\n");
1019                        ShowMessage("timeset <account_name> 0\n");
1020                        ShowMessage("  Gives an unlimited validity limit (0 = unlimited).\n");
1021                } else if (strcmp(command, "unban") == 0) {
1022                        ShowMessage("unban/unbanish <account name>\n");
1023                        ShowMessage("  Remove the banishment of an account.\n");
1024                        ShowMessage("  This command works like banset <account_name> 0.\n");
1025                } else if (strcmp(command, "unblock") == 0) {
1026                        ShowMessage("unblock <account name>\n");
1027                        ShowMessage("  Set state 0 (Account ok) to an account.\n");
1028                        ShowMessage("  This command works like state <account_name> 0.\n");
1029                } else if (strcmp(command, "version") == 0) {
1030                        ShowMessage("version\n");
1031                        ShowMessage("  Display the version of the login-server.\n");
1032                } else if (strcmp(command, "who") == 0) {
1033                        ShowMessage("who <account name>\n");
1034                        ShowMessage("  Displays complete information of an account.\n");
1035// quit
1036                } else if (strcmp(command, "quit") == 0 ||
1037                           strcmp(command, "exit") == 0 ||
1038                           strcmp(command, "end") == 0) {
1039                        ShowMessage("quit/end/exit\n");
1040                        ShowMessage("  End of the program of administration.\n");
1041// unknown command
1042                } else {
1043                        if (strlen(command) > 0)
1044                                ShowMessage("Unknown command [%s] for help. Displaying of all commands.\n", command);
1045                        ShowMessage(" aide/help/?                          -- Display this help\n");
1046                        ShowMessage(" aide/help/? [command]                -- Display the help of the command\n");
1047                        ShowMessage(" add <account_name> <sex> <password>  -- Create an account with default email\n");
1048                        ShowMessage(" ban/banish yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n");
1049                        ShowMessage(" banadd/ba <account_name> <modifier>  -- Add or substract time from the final\n");
1050                        ShowMessage("   example: ba apple +1m-2mn1s-2y        date of a banishment of an account\n");
1051                        ShowMessage(" banset/bs <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n");
1052                        ShowMessage(" banset/bs <account_name> 0           -- Un-banish an account\n");
1053                        ShowMessage(" block <account name>     -- Set state 5 (blocked by the GM Team) to an account\n");
1054                        ShowMessage(" check <account_name> <password>      -- Check the validity of a password\n");
1055                        ShowMessage(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n");
1056                        ShowMessage(" del <account name>                   -- Remove an account\n");
1057                        ShowMessage(" email <account_name> <email>         -- Modify an email of an account\n");
1058                        ShowMessage(" getcount                             -- Give the number of players online\n");
1059                        ShowMessage(" gm <account_name> [GM_level]         -- Modify the GM level of an account\n");
1060                        ShowMessage(" id <account name>                    -- Give the id of an account\n");
1061                        ShowMessage(" info <account_id>                    -- Display all information of an account\n");
1062                        ShowMessage(" kami <message>                       -- Sends a broadcast message (in yellow)\n");
1063                        ShowMessage(" kamib <message>                      -- Sends a broadcast message (in blue)\n");
1064                        ShowMessage(" language <language>                  -- Change the language of displaying.\n");
1065                        ShowMessage(" list/ls [First_id [Last_id]]         -- Display a list of accounts\n");
1066                        ShowMessage(" listBan/lsBan [First_id [Last_id] ]  -- Display a list of accounts\n");
1067                        ShowMessage("                                         with state or banished\n");
1068                        ShowMessage(" listGM/lsGM [First_id [Last_id]]     -- Display a list of GM accounts\n");
1069                        ShowMessage(" listOK/lsOK [First_id [Last_id] ]    -- Display a list of accounts\n");
1070                        ShowMessage("                                         without state and not banished\n");
1071                        ShowMessage(" memo <account_name> <memo>           -- Modify the memo of an account\n");
1072                        ShowMessage(" name <account_id>                    -- Give the name of an account\n");
1073                        ShowMessage(" passwd <account_name> <new_password> -- Change the password of an account\n");
1074                        ShowMessage(" quit/end/exit                        -- End of the program of administation\n");
1075                        ShowMessage(" reloadGM                             -- Reload GM configuration file\n");
1076                        ShowMessage(" search <expression>                  -- Seek accounts\n");
1077//                      ShowMessage(" search -e/-r/--expr/--regex <expressn> -- Seek accounts by regular-expression\n");
1078                        ShowMessage(" sex <nomcompte> <sexe>               -- Modify the sex of an account\n");
1079                        ShowMessage(" state <account_name> <new_state> <error_message_#7> -- Change the state\n");
1080                        ShowMessage(" timeadd/ta <account_name> <modifier> -- Add or substract time from the\n");
1081                        ShowMessage("   example: ta apple +1m-2mn1s-2y        validity limit of an account\n");
1082                        ShowMessage(" timeset/ts <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n");
1083                        ShowMessage(" timeset/ts <account_name> 0          -- Give a unlimited validity limit\n");
1084                        ShowMessage(" unban/unbanish <account name>        -- Remove the banishment of an account\n");
1085                        ShowMessage(" unblock <account name>               -- Set state 0 (Account ok) to an account\n");
1086                        ShowMessage(" version                              -- Gives the version of the login-server\n");
1087                        ShowMessage(" who <account name>                   -- Display all information of an account\n");
1088                        ShowMessage(" who <account name>                   -- Display all information of an account\n");
1089                        ShowMessage(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n");
1090                }
1091        }
1092}
1093
1094//-----------------------------
1095// Sub-function: add an account
1096//-----------------------------
1097int addaccount(char* param, int emailflag)
1098{
1099        char name[1023], sex[1023], email[1023], password[1023];
1100//      int i;
1101        WFIFOHEAD(login_fd,91);
1102
1103        memset(name, '\0', sizeof(name));
1104        memset(sex, '\0', sizeof(sex));
1105        memset(email, '\0', sizeof(email));
1106        memset(password, '\0', sizeof(password));
1107
1108        if (emailflag == 0) { // add command
1109                if (sscanf(param, "\"%[^\"]\" %s %[^\r\n]", name, sex, password) < 2 && // password can be void
1110                    sscanf(param, "'%[^']' %s %[^\r\n]", name, sex, password) < 2 && // password can be void
1111                    sscanf(param, "%s %s %[^\r\n]", name, sex, password) < 2) { // password can be void
1112                        if (defaultlanguage == 'F') {
1113                                ShowMessage("Entrez un nom de compte, un sexe et un mot de passe svp.\n");
1114                                ShowMessage("<exemple> add nomtest Male motdepassetest\n");
1115                                ladmin_log("Nombre incorrect de paramètres pour créer un compte (commande 'add').\n");
1116                        } else {
1117                                ShowMessage("Please input an account name, a sex and a password.\n");
1118                                ShowMessage("<example> add testname Male testpass\n");
1119                                ladmin_log("Incomplete parameters to create an account ('add' command).\n");
1120                        }
1121                        return 136;
1122                }
1123                strcpy(email, "a@a.com"); // default email
1124        } else { // 1: create command
1125                if (sscanf(param, "\"%[^\"]\" %s %s %[^\r\n]", name, sex, email, password) < 3 && // password can be void
1126                    sscanf(param, "'%[^']' %s %s %[^\r\n]", name, sex, email, password) < 3 && // password can be void
1127                    sscanf(param, "%s %s %s %[^\r\n]", name, sex, email, password) < 3) { // password can be void
1128                        if (defaultlanguage == 'F') {
1129                                ShowMessage("Entrez un nom de compte, un sexe et un mot de passe svp.\n");
1130                                ShowMessage("<exemple> create nomtest Male mo@mail.com motdepassetest\n");
1131                                ladmin_log("Nombre incorrect de paramètres pour créer un compte (commande 'create').\n");
1132                        } else {
1133                                ShowMessage("Please input an account name, a sex and a password.\n");
1134                                ShowMessage("<example> create testname Male my@mail.com testpass\n");
1135                                ladmin_log("Incomplete parameters to create an account ('create' command).\n");
1136                        }
1137                        return 136;
1138                }
1139        }
1140        if (verify_accountname(name) == 0) {
1141                return 102;
1142        }
1143
1144        sex[0] = TOUPPER(sex[0]);
1145        if (strchr("MF", sex[0]) == NULL) {
1146                if (defaultlanguage == 'F') {
1147                        ShowMessage("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
1148                        ladmin_log("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
1149                } else {
1150                        ShowMessage("Illegal gender [%s]. Please input M or F.\n", sex);
1151                        ladmin_log("Illegal gender [%s]. Please input M or F.\n", sex);
1152                }
1153                return 103;
1154        }
1155
1156        if (strlen(email) < 3) {
1157                if (defaultlanguage == 'F') {
1158                        ShowMessage("Email trop courte [%s]. Entrez une e-mail valide svp.\n", email);
1159                        ladmin_log("Email trop courte [%s]. Entrez une e-mail valide svp.\n", email);
1160                } else {
1161                        ShowMessage("Email is too short [%s]. Please input a valid e-mail.\n", email);
1162                        ladmin_log("Email is too short [%s]. Please input a valid e-mail.\n", email);
1163                }
1164                return 109;
1165        }
1166        if (strlen(email) > 39) {
1167                if (defaultlanguage == 'F') {
1168                        ShowMessage("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp.\n", email);
1169                        ladmin_log("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp.\n", email);
1170                } else {
1171                        ShowMessage("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n", email);
1172                        ladmin_log("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n", email);
1173                }
1174                return 109;
1175        }
1176        if (e_mail_check(email) == 0) {
1177                if (defaultlanguage == 'F') {
1178                        ShowMessage("Email incorrecte [%s]. Entrez une e-mail valide svp.\n", email);
1179                        ladmin_log("Email incorrecte [%s]. Entrez une e-mail valide svp.\n", email);
1180                } else {
1181                        ShowMessage("Invalid email [%s]. Please input a valid e-mail.\n", email);
1182                        ladmin_log("Invalid email [%s]. Please input a valid e-mail.\n", email);
1183                }
1184                return 109;
1185        }
1186
1187        if (strlen(password) == 0) {
1188                if (typepasswd(password) == 0)
1189                        return 108;
1190        }
1191        if (verify_password(password) == 0)
1192                return 104;
1193
1194        if (defaultlanguage == 'F') {
1195                ladmin_log("Envoi d'un requête au serveur de logins pour créer un compte.\n");
1196        } else {
1197                ladmin_log("Request to login-server to create an account.\n");
1198        }
1199
1200        WFIFOW(login_fd,0) = 0x7930;
1201        memcpy(WFIFOP(login_fd,2), name, 24);
1202        memcpy(WFIFOP(login_fd,26), password, 24);
1203        WFIFOB(login_fd,50) = sex[0];
1204        memcpy(WFIFOP(login_fd,51), email, 40);
1205        WFIFOSET(login_fd,91);
1206        bytes_to_read = 1;
1207
1208        return 0;
1209}
1210
1211//---------------------------------------------------------------------------------
1212// Sub-function: Add/substract time to the final date of a banishment of an account
1213//---------------------------------------------------------------------------------
1214int banaddaccount(char* param)
1215{
1216        char name[1023], modif[1023];
1217        int year, month, day, hour, minute, second;
1218        char * p_modif;
1219        int value, i;
1220        WFIFOHEAD(login_fd,38);
1221
1222        memset(name, '\0', sizeof(name));
1223        memset(modif, '\0', sizeof(modif));
1224        year = month = day = hour = minute = second = 0;
1225
1226        if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
1227            sscanf(param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
1228            sscanf(param, "%s %[^\r\n]", name, modif) < 2) {
1229                if (defaultlanguage == 'F') {
1230                        ShowMessage("Entrez un nom de compte et un modificateur svp.\n");
1231                        ShowMessage("  <exemple> banadd nomtest +1m-2mn1s-6y\n");
1232                        ShowMessage("            Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n");
1233                        ShowMessage("            et 6 ans dans le même temps.\n");
1234                        ladmin_log("Nombre incorrect de paramètres pour modifier la fin de ban d'un compte (commande 'banadd').\n");
1235                } else {
1236                        ShowMessage("Please input an account name and a modifier.\n");
1237                        ShowMessage("  <example>: banadd testname +1m-2mn1s-6y\n");
1238                        ShowMessage("             this example adds 1 month and 1 second, and substracts 2 minutes\n");
1239                        ShowMessage("             and 6 years at the same time.\n");
1240                        ladmin_log("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n");
1241                }
1242                return 136;
1243        }
1244        if (verify_accountname(name) == 0) {
1245                return 102;
1246        }
1247
1248        // lowercase for modif
1249        for (i = 0; modif[i]; i++)
1250                modif[i] = TOLOWER(modif[i]);
1251        p_modif = modif;
1252        while (strlen(p_modif) > 0) {
1253                value = atoi(p_modif);
1254                if (value == 0) {
1255                        p_modif++;
1256                } else {
1257                        if (p_modif[0] == '-' || p_modif[0] == '+')
1258                                p_modif++;
1259                        while (strlen(p_modif) > 0 && p_modif[0] >= '0' && p_modif[0] <= '9') {
1260                                p_modif++;
1261                        }
1262                        if (p_modif[0] == 's') {
1263                                second = value;
1264                                p_modif++;
1265                        } else if (p_modif[0] == 'm' && p_modif[1] == 'n') {
1266                                minute = value;
1267                                p_modif += 2;
1268                        } else if (p_modif[0] == 'h') {
1269                                hour = value;
1270                                p_modif++;
1271                        } else if (p_modif[0] == 'd' || p_modif[0] == 'j') {
1272                                day = value;
1273                                p_modif += 2;
1274                        } else if (p_modif[0] == 'm') {
1275                                month = value;
1276                                p_modif++;
1277                        } else if (p_modif[0] == 'y' || p_modif[0] == 'a') {
1278                                year = value;
1279                                p_modif++;
1280                        } else {
1281                                p_modif++;
1282                        }
1283                }
1284        }
1285
1286        if (defaultlanguage == 'F') {
1287                ShowMessage(" année:   %d\n", year);
1288                ShowMessage(" mois:    %d\n", month);
1289                ShowMessage(" jour:    %d\n", day);
1290                ShowMessage(" heure:   %d\n", hour);
1291                ShowMessage(" minute:  %d\n", minute);
1292                ShowMessage(" seconde: %d\n", second);
1293        } else {
1294                ShowMessage(" year:   %d\n", year);
1295                ShowMessage(" month:  %d\n", month);
1296                ShowMessage(" day:    %d\n", day);
1297                ShowMessage(" hour:   %d\n", hour);
1298                ShowMessage(" minute: %d\n", minute);
1299                ShowMessage(" second: %d\n", second);
1300        }
1301
1302        if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0) {
1303                if (defaultlanguage == 'F') {
1304                        ShowMessage("Vous devez entrer un ajustement avec cette commande, svp:\n");
1305                        ShowMessage("  Valeur d'ajustement (-1, 1, +1, etc...)\n");
1306                        ShowMessage("  Element modifié:\n");
1307                        ShowMessage("    a ou y: année\n");
1308                        ShowMessage("    m:      mois\n");
1309                        ShowMessage("    j ou d: jour\n");
1310                        ShowMessage("    h:      heure\n");
1311                        ShowMessage("    mn:     minute\n");
1312                        ShowMessage("    s:      seconde\n");
1313                        ShowMessage("  <exemple> banadd nomtest +1m-2mn1s-6y\n");
1314                        ShowMessage("            Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n");
1315                        ShowMessage("            et 6 ans dans le même temps.\n");
1316                        ladmin_log("Aucun ajustement n'est pas un ajustement (commande 'banadd').\n");
1317                } else {
1318                        ShowMessage("Please give an adjustment with this command:\n");
1319                        ShowMessage("  Adjustment value (-1, 1, +1, etc...)\n");
1320                        ShowMessage("  Modified element:\n");
1321                        ShowMessage("    a or y: year\n");
1322                        ShowMessage("    m: month\n");
1323                        ShowMessage("    j or d: day\n");
1324                        ShowMessage("    h: hour\n");
1325                        ShowMessage("    mn: minute\n");
1326                        ShowMessage("    s: second\n");
1327                        ShowMessage("  <example> banadd testname +1m-2mn1s-6y\n");
1328                        ShowMessage("            this example adds 1 month and 1 second, and substracts 2 minutes\n");
1329                        ShowMessage("            and 6 years at the same time.\n");
1330                        ladmin_log("No adjustment isn't an adjustment ('banadd' command).\n");
1331                }
1332                return 137;
1333        }
1334        if (year > 127 || year < -127) {
1335                if (defaultlanguage == 'F') {
1336                        ShowMessage("Entrez un ajustement d'années correct (de -127 à 127), svp.\n");
1337                        ladmin_log("Ajustement de l'année hors norme (commande 'banadd').\n");
1338                } else {
1339                        ShowMessage("Please give a correct adjustment for the years (from -127 to 127).\n");
1340                        ladmin_log("Abnormal adjustment for the year ('banadd' command).\n");
1341                }
1342                return 137;
1343        }
1344        if (month > 255 || month < -255) {
1345                if (defaultlanguage == 'F') {
1346                        ShowMessage("Entrez un ajustement de mois correct (de -255 à 255), svp.\n");
1347                        ladmin_log("Ajustement du mois hors norme (commande 'banadd').\n");
1348                } else {
1349                        ShowMessage("Please give a correct adjustment for the months (from -255 to 255).\n");
1350                        ladmin_log("Abnormal adjustment for the month ('banadd' command).\n");
1351                }
1352                return 137;
1353        }
1354        if (day > 32767 || day < -32767) {
1355                if (defaultlanguage == 'F') {
1356                        ShowMessage("Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n");
1357                        ladmin_log("Ajustement des jours hors norme (commande 'banadd').\n");
1358                } else {
1359                        ShowMessage("Please give a correct adjustment for the days (from -32767 to 32767).\n");
1360                        ladmin_log("Abnormal adjustment for the days ('banadd' command).\n");
1361                }
1362                return 137;
1363        }
1364        if (hour > 32767 || hour < -32767) {
1365                if (defaultlanguage == 'F') {
1366                        ShowMessage("Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n");
1367                        ladmin_log("Ajustement des heures hors norme (commande 'banadd').\n");
1368                } else {
1369                        ShowMessage("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
1370                        ladmin_log("Abnormal adjustment for the hours ('banadd' command).\n");
1371                }
1372                return 137;
1373        }
1374        if (minute > 32767 || minute < -32767) {
1375                if (defaultlanguage == 'F') {
1376                        ShowMessage("Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n");
1377                        ladmin_log("Ajustement des minutes hors norme (commande 'banadd').\n");
1378                } else {
1379                        ShowMessage("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
1380                        ladmin_log("Abnormal adjustment for the minutes ('banadd' command).\n");
1381                }
1382                return 137;
1383        }
1384        if (second > 32767 || second < -32767) {
1385                if (defaultlanguage == 'F') {
1386                        ShowMessage("Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n");
1387                        ladmin_log("Ajustement des secondes hors norme (commande 'banadd').\n");
1388                } else {
1389                        ShowMessage("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
1390                        ladmin_log("Abnormal adjustment for the seconds ('banadd' command).\n");
1391                }
1392                return 137;
1393        }
1394
1395        if (defaultlanguage == 'F') {
1396                ladmin_log("Envoi d'un requête au serveur de logins pour modifier la date d'un bannissement.\n");
1397        } else {
1398                ladmin_log("Request to login-server to modify a ban date/time.\n");
1399        }
1400
1401        WFIFOW(login_fd,0) = 0x794c;
1402        memcpy(WFIFOP(login_fd,2), name, 24);
1403        WFIFOW(login_fd,26) = (short)year;
1404        WFIFOW(login_fd,28) = (short)month;
1405        WFIFOW(login_fd,30) = (short)day;
1406        WFIFOW(login_fd,32) = (short)hour;
1407        WFIFOW(login_fd,34) = (short)minute;
1408        WFIFOW(login_fd,36) = (short)second;
1409        WFIFOSET(login_fd,38);
1410        bytes_to_read = 1;
1411
1412        return 0;
1413}
1414
1415//-----------------------------------------------------------------------
1416// Sub-function of sub-function banaccount, unbanaccount or bansetaccount
1417// Set the final date of a banishment of an account
1418//-----------------------------------------------------------------------
1419int bansetaccountsub(char* name, char* date, char* time)
1420{
1421        int year, month, day, hour, minute, second;
1422        time_t unban_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
1423        struct tm *tmtime;
1424        WFIFOHEAD(login_fd,30);
1425
1426        year = month = day = hour = minute = second = 0;
1427        unban_time = 0;
1428        tmtime = localtime(&unban_time); // initialize
1429
1430        if (verify_accountname(name) == 0) {
1431                return 102;
1432        }
1433
1434        if (atoi(date) != 0 &&
1435            ((sscanf(date, "%d/%d/%d", &year, &month, &day) < 3 &&
1436              sscanf(date, "%d-%d-%d", &year, &month, &day) < 3 &&
1437              sscanf(date, "%d.%d.%d", &year, &month, &day) < 3) ||
1438             sscanf(time, "%d:%d:%d", &hour, &minute, &second) < 3)) {
1439                if (defaultlanguage == 'F') {
1440                        ShowMessage("Entrez une date et une heure svp (format: aaaa/mm/jj hh:mm:ss).\n");
1441                        ShowMessage("Vous pouvez aussi mettre 0 à la place si vous utilisez la commande 'banset'.\n");
1442                        ladmin_log("Format incorrect pour la date/heure (commande'banset' ou 'ban').\n");
1443                } else {
1444                        ShowMessage("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
1445                        ShowMessage("You can imput 0 instead of if you use 'banset' command.\n");
1446                        ladmin_log("Invalid format for the date/time ('banset' or 'ban' command).\n");
1447                }
1448                return 102;
1449        }
1450
1451        if (atoi(date) == 0) {
1452                unban_time = 0;
1453        } else {
1454                if (year < 70) {
1455                        year = year + 100;
1456                }
1457                if (year >= 1900) {
1458                        year = year - 1900;
1459                }
1460                if (month < 1 || month > 12) {
1461                        if (defaultlanguage == 'F') {
1462                                ShowMessage("Entrez un mois correct svp (entre 1 et 12).\n");
1463                                ladmin_log("Mois incorrect pour la date (command 'banset' ou 'ban').\n");
1464                        } else {
1465                                ShowMessage("Please give a correct value for the month (from 1 to 12).\n");
1466                                ladmin_log("Invalid month for the date ('banset' or 'ban' command).\n");
1467                        }
1468                        return 102;
1469                }
1470                month = month - 1;
1471                if (day < 1 || day > 31) {
1472                        if (defaultlanguage == 'F') {
1473                                ShowMessage("Entrez un jour correct svp (entre 1 et 31).\n");
1474                                ladmin_log("Jour incorrect pour la date (command 'banset' ou 'ban').\n");
1475                        } else {
1476                                ShowMessage("Please give a correct value for the day (from 1 to 31).\n");
1477                                ladmin_log("Invalid day for the date ('banset' or 'ban' command).\n");
1478                        }
1479                        return 102;
1480                }
1481                if (((month == 3 || month == 5 || month == 8 || month == 10) && day > 30) ||
1482                    (month == 1 && day > 29)) {
1483                        if (defaultlanguage == 'F') {
1484                                ShowMessage("Entrez un jour correct en fonction du mois (%d) svp.\n", month);
1485                                ladmin_log("Jour incorrect pour ce mois correspondant (command 'banset' ou 'ban').\n");
1486                        } else {
1487                                ShowMessage("Please give a correct value for a day of this month (%d).\n", month);
1488                                ladmin_log("Invalid day for this month ('banset' or 'ban' command).\n");
1489                        }
1490                        return 102;
1491                }
1492                if (hour < 0 || hour > 23) {
1493                        if (defaultlanguage == 'F') {
1494                                ShowMessage("Entrez une heure correcte svp (entre 0 et 23).\n");
1495                                ladmin_log("Heure incorrecte pour l'heure (command 'banset' ou 'ban').\n");
1496                        } else {
1497                                ShowMessage("Please give a correct value for the hour (from 0 to 23).\n");
1498                                ladmin_log("Invalid hour for the time ('banset' or 'ban' command).\n");
1499                        }
1500                        return 102;
1501                }
1502                if (minute < 0 || minute > 59) {
1503                        if (defaultlanguage == 'F') {
1504                                ShowMessage("Entrez des minutes correctes svp (entre 0 et 59).\n");
1505                                ladmin_log("Minute incorrecte pour l'heure (command 'banset' ou 'ban').\n");
1506                        } else {
1507                                ShowMessage("Please give a correct value for the minutes (from 0 to 59).\n");
1508                                ladmin_log("Invalid minute for the time ('banset' or 'ban' command).\n");
1509                        }
1510                        return 102;
1511                }
1512                if (second < 0 || second > 59) {
1513                        if (defaultlanguage == 'F') {
1514                                ShowMessage("Entrez des secondes correctes svp (entre 0 et 59).\n");
1515                                ladmin_log("Seconde incorrecte pour l'heure (command 'banset' ou 'ban').\n");
1516                        } else {
1517                                ShowMessage("Please give a correct value for the seconds (from 0 to 59).\n");
1518                                ladmin_log("Invalid second for the time ('banset' or 'ban' command).\n");
1519                        }
1520                        return 102;
1521                }
1522                tmtime->tm_year = year;
1523                tmtime->tm_mon = month;
1524                tmtime->tm_mday = day;
1525                tmtime->tm_hour = hour;
1526                tmtime->tm_min = minute;
1527                tmtime->tm_sec = second;
1528                tmtime->tm_isdst = -1; // -1: no winter/summer time modification
1529                unban_time = mktime(tmtime);
1530                if (unban_time == -1) {
1531                        if (defaultlanguage == 'F') {
1532                                ShowMessage("Date incorrecte.\n");
1533                                ShowMessage("Entrez une date et une heure svp (format: aaaa/mm/jj hh:mm:ss).\n");
1534                                ShowMessage("Vous pouvez aussi mettre 0 à la place si vous utilisez la commande 'banset'.\n");
1535                                ladmin_log("Date incorrecte. (command 'banset' ou 'ban').\n");
1536                        } else {
1537                                ShowMessage("Invalid date.\n");
1538                                ShowMessage("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
1539                                ShowMessage("You can imput 0 instead of if you use 'banset' command.\n");
1540                                ladmin_log("Invalid date. ('banset' or 'ban' command).\n");
1541                        }
1542                        return 102;
1543                }
1544        }
1545
1546        if (defaultlanguage == 'F') {
1547                ladmin_log("Envoi d'un requête au serveur de logins pour fixer un ban.\n");
1548        } else {
1549                ladmin_log("Request to login-server to set a ban.\n");
1550        }
1551
1552        WFIFOW(login_fd,0) = 0x794a;
1553        memcpy(WFIFOP(login_fd,2), name, 24);
1554        WFIFOL(login_fd,26) = (int)unban_time;
1555        WFIFOSET(login_fd,30);
1556        bytes_to_read = 1;
1557
1558        return 0;
1559}
1560
1561//---------------------------------------------------------------------
1562// Sub-function: Set the final date of a banishment of an account (ban)
1563//---------------------------------------------------------------------
1564int banaccount(char* param)
1565{
1566        char name[1023], date[1023], time[1023];
1567
1568        memset(name, '\0', sizeof(name));
1569        memset(date, '\0', sizeof(date));
1570        memset(time, '\0', sizeof(time));
1571
1572        if (sscanf(param, "%s %s \"%[^\"]\"", date, time, name) < 3 &&
1573            sscanf(param, "%s %s '%[^']'", date, time, name) < 3 &&
1574            sscanf(param, "%s %s %[^\r\n]", date, time, name) < 3) {
1575                if (defaultlanguage == 'F') {
1576                        ShowMessage("Entrez un nom de compte, une date et une heure svp.\n");
1577                        ShowMessage("<exemple>: banset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
1578                        ShowMessage("           banset <nom_du_compte> 0    (0 = dé-bani)\n");
1579                        ShowMessage("           ban/banish aaaa/mm/jj hh:mm:ss <nom du compte>\n");
1580                        ShowMessage("           unban/unbanish <nom du compte>\n");
1581                        ShowMessage("           Heure par défaut [hh:mm:ss]: 23:59:59.\n");
1582                        ladmin_log("Nombre incorrect de paramètres pour fixer un ban (commande 'banset' ou 'ban').\n");
1583                } else {
1584                        ShowMessage("Please input an account name, a date and a hour.\n");
1585                        ShowMessage("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
1586                        ShowMessage("           banset <account_name> 0   (0 = un-banished)\n");
1587                        ShowMessage("           ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
1588                        ShowMessage("           unban/unbanish <account name>\n");
1589                        ShowMessage("           Default time [hh:mm:ss]: 23:59:59.\n");
1590                        ladmin_log("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
1591                }
1592                return 136;
1593        }
1594
1595        return bansetaccountsub(name, date, time);
1596}
1597
1598//------------------------------------------------------------------------
1599// Sub-function: Set the final date of a banishment of an account (banset)
1600//------------------------------------------------------------------------
1601int bansetaccount(char* param)
1602{
1603        char name[1023], date[1023], time[1023];
1604
1605        memset(name, '\0', sizeof(name));
1606        memset(date, '\0', sizeof(date));
1607        memset(time, '\0', sizeof(time));
1608
1609        if (sscanf(param, "\"%[^\"]\" %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
1610            sscanf(param, "'%[^']' %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
1611            sscanf(param, "%s %s %[^\r\n]", name, date, time) < 2) { // if date = 0, time can be void
1612                if (defaultlanguage == 'F') {
1613                        ShowMessage("Entrez un nom de compte, une date et une heure svp.\n");
1614                        ShowMessage("<exemple>: banset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
1615                        ShowMessage("           banset <nom_du_compte> 0    (0 = dé-bani)\n");
1616                        ShowMessage("           ban/banish aaaa/mm/jj hh:mm:ss <nom du compte>\n");
1617                        ShowMessage("           unban/unbanish <nom du compte>\n");
1618                        ShowMessage("           Heure par défaut [hh:mm:ss]: 23:59:59.\n");
1619                        ladmin_log("Nombre incorrect de paramètres pour fixer un ban (commande 'banset' ou 'ban').\n");
1620                } else {
1621                        ShowMessage("Please input an account name, a date and a hour.\n");
1622                        ShowMessage("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
1623                        ShowMessage("           banset <account_name> 0   (0 = un-banished)\n");
1624                        ShowMessage("           ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
1625                        ShowMessage("           unban/unbanish <account name>\n");
1626                        ShowMessage("           Default time [hh:mm:ss]: 23:59:59.\n");
1627                        ladmin_log("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
1628                }
1629                return 136;
1630        }
1631
1632        if (time[0] == '\0')
1633                strcpy(time, "23:59:59");
1634
1635        return bansetaccountsub(name, date, time);
1636}
1637
1638//-------------------------------------------------
1639// Sub-function: unbanishment of an account (unban)
1640//-------------------------------------------------
1641int unbanaccount(char* param)
1642{
1643        char name[1023];
1644
1645        memset(name, '\0', sizeof(name));
1646
1647        if (strlen(param) == 0 ||
1648            (sscanf(param, "\"%[^\"]\"", name) < 1 &&
1649             sscanf(param, "'%[^']'", name) < 1 &&
1650             sscanf(param, "%[^\r\n]", name) < 1) ||
1651             strlen(name) == 0) {
1652                if (defaultlanguage == 'F') {
1653                        ShowMessage("Entrez un nom de compte svp.\n");
1654                        ShowMessage("<exemple>: banset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
1655                        ShowMessage("           banset <nom_du_compte> 0    (0 = dé-bani)\n");
1656                        ShowMessage("           ban/banish aaaa/mm/jj hh:mm:ss <nom du compte>\n");
1657                        ShowMessage("           unban/unbanish <nom du compte>\n");
1658                        ShowMessage("           Heure par défaut [hh:mm:ss]: 23:59:59.\n");
1659                        ladmin_log("Nombre incorrect de paramètres pour fixer un ban (commande 'unban').\n");
1660                } else {
1661                        ShowMessage("Please input an account name.\n");
1662                        ShowMessage("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
1663                        ShowMessage("           banset <account_name> 0   (0 = un-banished)\n");
1664                        ShowMessage("           ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
1665                        ShowMessage("           unban/unbanish <account name>\n");
1666                        ShowMessage("           Default time [hh:mm:ss]: 23:59:59.\n");
1667                        ladmin_log("Incomplete parameters to set a ban ('unban' command).\n");
1668                }
1669                return 136;
1670        }
1671
1672        return bansetaccountsub(name, "0", "");
1673}
1674
1675//---------------------------------------------------------
1676// Sub-function: Asking to check the validity of a password
1677// (Note: never send back a password with login-server!! security of passwords)
1678//---------------------------------------------------------
1679int checkaccount(char* param)
1680{
1681        char name[1023], password[1023];
1682        WFIFOHEAD(login_fd,50);
1683
1684        memset(name, '\0', sizeof(name));
1685        memset(password, '\0', sizeof(password));
1686
1687        if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 && // password can be void
1688            sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 && // password can be void
1689            sscanf(param, "%s %[^\r\n]", name, password) < 1) { // password can be void
1690                if (defaultlanguage == 'F') {
1691                        ShowMessage("Entrez un nom de compte svp.\n");
1692                        ShowMessage("<exemple> check testname motdepasse\n");
1693                        ladmin_log("Nombre incorrect de paramètres pour tester le mot d'un passe d'un compte (commande 'check').\n");
1694                } else {
1695                        ShowMessage("Please input an account name.\n");
1696                        ShowMessage("<example> check testname password\n");
1697                        ladmin_log("Incomplete parameters to check the password of an account ('check' command).\n");
1698                }
1699                return 136;
1700        }
1701
1702        if (verify_accountname(name) == 0) {
1703                return 102;
1704        }
1705
1706        if (strlen(password) == 0) {
1707                if (typepasswd(password) == 0)
1708                        return 134;
1709        }
1710        if (verify_password(password) == 0)
1711                return 131;
1712
1713        if (defaultlanguage == 'F') {
1714                ladmin_log("Envoi d'un requête au serveur de logins pour test un mot de passe.\n");
1715        } else {
1716                ladmin_log("Request to login-server to check a password.\n");
1717        }
1718
1719        WFIFOW(login_fd,0) = 0x793a;
1720        memcpy(WFIFOP(login_fd,2), name, 24);
1721        memcpy(WFIFOP(login_fd,26), password, 24);
1722        WFIFOSET(login_fd,50);
1723        bytes_to_read = 1;
1724
1725        return 0;
1726}
1727
1728//------------------------------------------------
1729// Sub-function: Asking for deletion of an account
1730//------------------------------------------------
1731int delaccount(char* param)
1732{
1733        char name[1023];
1734        char letter;
1735        char confirm[1023];
1736        int i;
1737        WFIFOHEAD(login_fd,26);
1738
1739        memset(name, '\0', sizeof(name));
1740
1741        if (strlen(param) == 0 ||
1742            (sscanf(param, "\"%[^\"]\"", name) < 1 &&
1743             sscanf(param, "'%[^']'", name) < 1 &&
1744             sscanf(param, "%[^\r\n]", name) < 1) ||
1745             strlen(name) == 0) {
1746                if (defaultlanguage == 'F') {
1747                        ShowMessage("Entrez un nom de compte svp.\n");
1748                        ShowMessage("<exemple> del nomtestasupprimer\n");
1749                        ladmin_log("Aucun nom donné pour supprimer un compte (commande 'delete').\n");
1750                } else {
1751                        ShowMessage("Please input an account name.\n");
1752                        ShowMessage("<example> del testnametodelete\n");
1753                        ladmin_log("No name given to delete an account ('delete' command).\n");
1754                }
1755                return 136;
1756        }
1757
1758        if (verify_accountname(name) == 0) {
1759                return 102;
1760        }
1761
1762        memset(confirm, '\0', sizeof(confirm));
1763        while ((confirm[0] != 'o' || defaultlanguage != 'F') && confirm[0] != 'n' && (confirm[0] != 'y' || defaultlanguage == 'F')) {
1764                if (defaultlanguage == 'F')
1765                        ShowMessage("\033[1;36m ** Etes-vous vraiment sûr de vouloir SUPPRIMER le compte [$userid]? (o/n) > \033[0m");
1766                else
1767                        ShowMessage("\033[1;36m ** Are you really sure to DELETE account [$userid]? (y/n) > \033[0m");
1768                fflush(stdout);
1769                memset(confirm, '\0', sizeof(confirm));
1770                i = 0;
1771                while ((letter = getchar()) != '\n')
1772                        confirm[i++] = letter;
1773        }
1774
1775        if (confirm[0] == 'n') {
1776                if (defaultlanguage == 'F') {
1777                        ShowMessage("Suppression annulée.\n");
1778                        ladmin_log("Suppression annulée par l'utilisateur (commande 'delete').\n");
1779                } else {
1780                        ShowMessage("Deletion canceled.\n");
1781                        ladmin_log("Deletion canceled by user ('delete' command).\n");
1782                }
1783                return 121;
1784        }
1785
1786        if (defaultlanguage == 'F') {
1787                ladmin_log("Envoi d'un requête au serveur de logins pour détruire un compte.\n");
1788        } else {
1789                ladmin_log("Request to login-server to delete an acount.\n");
1790        }
1791
1792        WFIFOW(login_fd,0) = 0x7932;
1793        memcpy(WFIFOP(login_fd,2), name, 24);
1794        WFIFOSET(login_fd,26);
1795        bytes_to_read = 1;
1796
1797        return 0;
1798}
1799
1800//----------------------------------------------------------
1801// Sub-function: Asking to modification of an account e-mail
1802//----------------------------------------------------------
1803int changeemail(char* param)
1804{
1805        char name[1023], email[1023];
1806        WFIFOHEAD(login_fd,66);
1807
1808        memset(name, '\0', sizeof(name));
1809        memset(email, '\0', sizeof(email));
1810
1811        if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, email) < 2 &&
1812            sscanf(param, "'%[^']' %[^\r\n]", name, email) < 2 &&
1813            sscanf(param, "%s %[^\r\n]", name, email) < 2) {
1814                if (defaultlanguage == 'F') {
1815                        ShowMessage("Entrez un nom de compte et une email svp.\n");
1816                        ShowMessage("<exemple> email testname nouveauemail\n");
1817                        ladmin_log("Nombre incorrect de paramètres pour changer l'email d'un compte (commande 'email').\n");
1818                } else {
1819                        ShowMessage("Please input an account name and an email.\n");
1820                        ShowMessage("<example> email testname newemail\n");
1821                        ladmin_log("Incomplete parameters to change the email of an account ('email' command).\n");
1822                }
1823                return 136;
1824        }
1825
1826        if (verify_accountname(name) == 0) {
1827                return 102;
1828        }
1829
1830        if (strlen(email) < 3) {
1831                if (defaultlanguage == 'F') {
1832                        ShowMessage("Email trop courte [%s]. Entrez une e-mail valide svp.\n", email);
1833                        ladmin_log("Email trop courte [%s]. Entrez une e-mail valide svp.\n", email);
1834                } else {
1835                        ShowMessage("Email is too short [%s]. Please input a valid e-mail.\n", email);
1836                        ladmin_log("Email is too short [%s]. Please input a valid e-mail.\n", email);
1837                }
1838                return 109;
1839        }
1840        if (strlen(email) > 39) {
1841                if (defaultlanguage == 'F') {
1842                        ShowMessage("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp.\n", email);
1843                        ladmin_log("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp.\n", email);
1844                } else {
1845                        ShowMessage("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n", email);
1846                        ladmin_log("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n", email);
1847                }
1848                return 109;
1849        }
1850        if (e_mail_check(email) == 0) {
1851                if (defaultlanguage == 'F') {
1852                        ShowMessage("Email incorrecte [%s]. Entrez une e-mail valide svp.\n", email);
1853                        ladmin_log("Email incorrecte [%s]. Entrez une e-mail valide svp.\n", email);
1854                } else {
1855                        ShowMessage("Invalid email [%s]. Please input a valid e-mail.\n", email);
1856                        ladmin_log("Invalid email [%s]. Please input a valid e-mail.\n", email);
1857                }
1858                return 109;
1859        }
1860
1861        if (defaultlanguage == 'F') {
1862                ladmin_log("Envoi d'un requête au serveur de logins pour changer une email.\n");
1863        } else {
1864                ladmin_log("Request to login-server to change an email.\n");
1865        }
1866
1867        WFIFOW(login_fd,0) = 0x7940;
1868        memcpy(WFIFOP(login_fd,2), name, 24);
1869        memcpy(WFIFOP(login_fd,26), email, 40);
1870        WFIFOSET(login_fd,66);
1871        bytes_to_read = 1;
1872
1873        return 0;
1874}
1875
1876//-----------------------------------------------------
1877// Sub-function: Asking of the number of online players
1878//-----------------------------------------------------
1879int getlogincount(void)
1880{
1881        WFIFOHEAD(login_fd,2);
1882        if (defaultlanguage == 'F') {
1883                ladmin_log("Envoi d'un requête au serveur de logins pour obtenir le nombre de joueurs en jeu.\n");
1884        } else {
1885                ladmin_log("Request to login-server to obtain the # of online players.\n");
1886        }
1887
1888        WFIFOW(login_fd,0) = 0x7938;
1889        WFIFOSET(login_fd,2);
1890        bytes_to_read = 1;
1891
1892        return 0;
1893}
1894
1895//----------------------------------------------------------
1896// Sub-function: Asking to modify the GM level of an account
1897//----------------------------------------------------------
1898int changegmlevel(char* param)
1899{
1900        char name[1023];
1901        int GM_level;
1902        WFIFOHEAD(login_fd,27);
1903
1904        memset(name, '\0', sizeof(name));
1905        GM_level = 0;
1906
1907        if (sscanf(param, "\"%[^\"]\" %d", name, &GM_level) < 1 &&
1908            sscanf(param, "'%[^']' %d", name, &GM_level) < 1 &&
1909            sscanf(param, "%s %d", name, &GM_level) < 1) {
1910                if (defaultlanguage == 'F') {
1911                        ShowMessage("Entrez un nom de compte et un niveau de GM svp.\n");
1912                        ShowMessage("<exemple> gm nomtest 80\n");
1913                        ladmin_log("Nombre incorrect de paramètres pour changer le Niveau de GM d'un compte (commande 'gm').\n");
1914                } else {
1915                        ShowMessage("Please input an account name and a GM level.\n");
1916                        ShowMessage("<example> gm testname 80\n");
1917                        ladmin_log("Incomplete parameters to change the GM level of an account ('gm' command).\n");
1918                }
1919                return 136;
1920        }
1921
1922        if (verify_accountname(name) == 0) {
1923                return 102;
1924        }
1925
1926        if (GM_level < 0 || GM_level > 99) {
1927                if (defaultlanguage == 'F') {
1928                        ShowMessage("Niveau de GM incorrect [%d]. Entrez une valeur de 0 à 99 svp.\n", GM_level);
1929                        ladmin_log("Niveau de GM incorrect [%d]. La valeur peut être de 0 à 99.\n", GM_level);
1930                } else {
1931                        ShowMessage("Illegal GM level [%d]. Please input a value from 0 to 99.\n", GM_level);
1932                        ladmin_log("Illegal GM level [%d]. The value can be from 0 to 99.\n", GM_level);
1933                }
1934                return 103;
1935        }
1936
1937        if (defaultlanguage == 'F') {
1938                ladmin_log("Envoi d'un requête au serveur de logins pour changer un niveau de GM.\n");
1939        } else {
1940                ladmin_log("Request to login-server to change a GM level.\n");
1941        }
1942
1943        WFIFOW(login_fd,0) = 0x793e;
1944        memcpy(WFIFOP(login_fd,2), name, 24);
1945        WFIFOB(login_fd,26) = GM_level;
1946        WFIFOSET(login_fd,27);
1947        bytes_to_read = 1;
1948
1949        return 0;
1950}
1951
1952//---------------------------------------------
1953// Sub-function: Asking to obtain an account id
1954//---------------------------------------------
1955int idaccount(char* param)
1956{
1957        char name[1023];
1958        WFIFOHEAD(login_fd,26);
1959
1960        memset(name, '\0', sizeof(name));
1961
1962        if (strlen(param) == 0 ||
1963            (sscanf(param, "\"%[^\"]\"", name) < 1 &&
1964             sscanf(param, "'%[^']'", name) < 1 &&
1965             sscanf(param, "%[^\r\n]", name) < 1) ||
1966             strlen(name) == 0) {
1967                if (defaultlanguage == 'F') {
1968                        ShowMessage("Entrez un nom de compte svp.\n");
1969                        ShowMessage("<exemple> id nomtest\n");
1970                        ladmin_log("Aucun nom donné pour rechecher l'id d'un compte (commande 'id').\n");
1971                } else {
1972                        ShowMessage("Please input an account name.\n");
1973                        ShowMessage("<example> id testname\n");
1974                        ladmin_log("No name given to search an account id ('id' command).\n");
1975                }
1976                return 136;
1977        }
1978
1979        if (verify_accountname(name) == 0) {
1980                return 102;
1981        }
1982
1983        if (defaultlanguage == 'F') {
1984                ladmin_log("Envoi d'un requête au serveur de logins pour connaître l'id d'un compte.\n");
1985        } else {
1986                ladmin_log("Request to login-server to know an account id.\n");
1987        }
1988
1989        WFIFOW(login_fd,0) = 0x7944;
1990        memcpy(WFIFOP(login_fd,2), name, 24);
1991        WFIFOSET(login_fd,26);
1992        bytes_to_read = 1;
1993
1994        return 0;
1995}
1996
1997//----------------------------------------------------------------------------
1998// Sub-function: Asking to displaying information about an account (by its id)
1999//----------------------------------------------------------------------------
2000int infoaccount(int account_id)
2001{
2002        WFIFOHEAD(login_fd,6);
2003        if (account_id < 0) {
2004                if (defaultlanguage == 'F') {
2005                        ShowMessage("Entrez un id ayant une valeur positive svp.\n");
2006                        ladmin_log("Une valeur négative a été donné pour trouver le compte.\n");
2007                } else {
2008                        ShowMessage("Please input a positive value for the id.\n");
2009                        ladmin_log("Negative value was given to found the account.\n");
2010                }
2011                return 136;
2012        }
2013
2014        if (defaultlanguage == 'F') {
2015                ladmin_log("Envoi d'un requête au serveur de logins pour obtenir le information d'un compte (par l'id).\n");
2016        } else {
2017                ladmin_log("Request to login-server to obtain information about an account (by its id).\n");
2018        }
2019
2020        WFIFOW(login_fd,0) = 0x7954;
2021        WFIFOL(login_fd,2) = account_id;
2022        WFIFOSET(login_fd,6);
2023        bytes_to_read = 1;
2024
2025        return 0;
2026}
2027
2028//---------------------------------------
2029// Sub-function: Send a broadcast message
2030//---------------------------------------
2031int sendbroadcast(short type, char* message)
2032{
2033        int len = strlen(message);
2034        WFIFOHEAD(login_fd,9+len);
2035        if (len == 0) {
2036                if (defaultlanguage == 'F') {
2037                        ShowMessage("Entrez un message svp.\n");
2038                        if (type == 0) {
2039                                ShowMessage("<exemple> kami un message\n");
2040                        } else {
2041                                ShowMessage("<exemple> kamib un message\n");
2042                        }
2043                        ladmin_log("Le message est vide (commande 'kami(b)').\n");
2044                } else {
2045                        ShowMessage("Please input a message.\n");
2046                        if (type == 0) {
2047                                ShowMessage("<example> kami a message\n");
2048                        } else {
2049                                ShowMessage("<example> kamib a message\n");
2050                        }
2051                        ladmin_log("The message is void ('kami(b)' command).\n");
2052                }
2053                return 136;
2054        }
2055        len++; //+'\0'
2056        WFIFOW(login_fd,0) = 0x794e;
2057        WFIFOW(login_fd,2) = type;
2058        WFIFOL(login_fd,4) = len;
2059        memcpy(WFIFOP(login_fd,8), message, len);
2060        WFIFOSET(login_fd,8+len);
2061        bytes_to_read = 1;
2062
2063        return 0;
2064}
2065
2066//--------------------------------------------
2067// Sub-function: Change language of displaying
2068//--------------------------------------------
2069int changelanguage(char* language)
2070{
2071        if (strlen(language) == 0) {
2072                if (defaultlanguage == 'F') {
2073                        ShowMessage("Entrez une langue svp.\n");
2074                        ShowMessage("<exemple> language english\n");
2075                        ShowMessage("          language français\n");
2076                        ladmin_log("La langue est vide (commande 'language').\n");
2077                } else {
2078                        ShowMessage("Please input a language.\n");
2079                        ShowMessage("<example> language english\n");
2080                        ShowMessage("          language français\n");
2081                        ladmin_log("The language is void ('language' command).\n");
2082                }
2083                return 136;
2084        }
2085
2086        language[0] = TOUPPER(language[0]);
2087        if (language[0] == 'F' || language[0] == 'E') {
2088                defaultlanguage = language[0];
2089                if (defaultlanguage == 'F') {
2090                        ShowMessage("Changement de la langue d'affichage en Français.\n");
2091                        ladmin_log("Changement de la langue d'affichage en Français.\n");
2092                } else {
2093                        ShowMessage("Displaying language changed to English.\n");
2094                        ladmin_log("Displaying language changed to English.\n");
2095                }
2096        } else {
2097                if (defaultlanguage == 'F') {
2098                        ShowMessage("Langue non paramétrée (langues possibles: 'Français' ou 'English').\n");
2099                        ladmin_log("Langue non paramétrée (Français ou English nécessaire).\n");
2100                } else {
2101                        ShowMessage("Undefined language (possible languages: Français or English).\n");
2102                        ladmin_log("Undefined language (must be Français or English).\n");
2103                }
2104        }
2105
2106        return 0;
2107}
2108
2109//--------------------------------------------------------
2110// Sub-function: Asking to Displaying of the accounts list
2111//--------------------------------------------------------
2112int listaccount(char* param, int type)
2113{
2114//int list_first, list_last, list_type; // parameter to display a list of accounts
2115        int i;
2116        WFIFOHEAD(login_fd,10);
2117
2118        list_type = type;
2119
2120        // set default values
2121        list_first = 0;
2122        list_last = 0;
2123
2124        if (list_type == 1) { // if listgm
2125                // get all accounts = use default
2126        } else if (list_type == 2) { // if search
2127                for (i = 0; param[i]; i++)
2128                        param[i] = TOLOWER(param[i]);
2129                // get all accounts = use default
2130        } else if (list_type == 3) { // if listban
2131                // get all accounts = use default
2132        } else if (list_type == 4) { // if listok
2133                // get all accounts = use default
2134        } else { // if list (list_type == 0)
2135                switch(sscanf(param, "%d %d", &list_first, &list_last)) {
2136                case 0:
2137                        // get all accounts = use default
2138                        break;
2139                case 1:
2140                        list_last = 0;
2141                        // use tests of the following value
2142                default:
2143                        if (list_first < 0)
2144                                list_first = 0;
2145                        if (list_last < list_first || list_last < 0)
2146                                list_last = 0;
2147                        break;
2148                }
2149        }
2150
2151        if (defaultlanguage == 'F') {
2152                ladmin_log("Envoi d'un requête au serveur de logins pour obtenir la liste des comptes de %d à %d.\n", list_first, list_last);
2153        } else {
2154                ladmin_log("Request to login-server to obtain the list of accounts from %d to %d.\n", list_first, list_last);
2155        }
2156
2157        WFIFOW(login_fd,0) = 0x7920;
2158        WFIFOL(login_fd,2) = list_first;
2159        WFIFOL(login_fd,6) = list_last;
2160        WFIFOSET(login_fd,10);
2161        bytes_to_read = 1;
2162
2163        //          0123456789 01 01234567890123456789012301234 012345 0123456789012345678901234567
2164        if (defaultlanguage == 'F') {
2165                ShowMessage(" id_compte GM nom_utilisateur         sexe   count statut\n");
2166        } else {
2167                ShowMessage("account_id GM user_name               sex    count state\n");
2168        }
2169        ShowMessage("-------------------------------------------------------------------------------\n");
2170        list_count = 0;
2171
2172        return 0;
2173}
2174
2175//--------------------------------------------
2176// Sub-function: Asking to modify a memo field
2177//--------------------------------------------
2178int changememo(char* param)
2179{
2180        char name[1023], memo[1023];
2181        WFIFOHEAD(login_fd,28+255);
2182
2183        memset(name, '\0', sizeof(name));
2184        memset(memo, '\0', sizeof(memo));
2185
2186        if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, memo) < 1 && // memo can be void
2187            sscanf(param, "'%[^']' %[^\r\n]", name, memo) < 1 && // memo can be void
2188            sscanf(param, "%s %[^\r\n]", name, memo) < 1) { // memo can be void
2189                if (defaultlanguage == 'F') {
2190                        ShowMessage("Entrez un nom de compte et un mémo svp.\n");
2191                        ShowMessage("<exemple> memo nomtest nouveau memo\n");
2192                        ladmin_log("Nombre incorrect de paramètres pour changer le mémo d'un compte (commande 'email').\n");
2193                } else {
2194                        ShowMessage("Please input an account name and a memo.\n");
2195                        ShowMessage("<example> memo testname new memo\n");
2196                        ladmin_log("Incomplete parameters to change the memo of an account ('email' command).\n");
2197                }
2198                return 136;
2199        }
2200
2201        if (verify_accountname(name) == 0) {
2202                return 102;
2203        }
2204
2205        if (strlen(memo) > 254) {
2206                if (defaultlanguage == 'F') {
2207                        ShowMessage("Mémo trop long (%lu caractères).\n", (unsigned long)strlen(memo));
2208                        ShowMessage("Entrez un mémo de 254 caractères maximum svp.\n");
2209                        ladmin_log("Mémo trop long (%d caractères). Entrez un mémo de 254 caractères maximum svp.\n", strlen(memo));
2210                } else {
2211                        ShowMessage("Memo is too long (%lu characters).\n", (unsigned long)strlen(memo));
2212                        ShowMessage("Please input a memo of 254 bytes at the maximum.\n");
2213                        ladmin_log("Email is too long (%d characters). Please input a memo of 254 bytes at the maximum.\n", strlen(memo));
2214                }
2215                return 102;
2216        }
2217
2218        if (defaultlanguage == 'F') {
2219                ladmin_log("Envoi d'un requête au serveur de logins pour changer un mémo.\n");
2220        } else {
2221                ladmin_log("Request to login-server to change a memo.\n");
2222        }
2223
2224        WFIFOW(login_fd,0) = 0x7942;
2225        memcpy(WFIFOP(login_fd,2), name, 24);
2226        WFIFOW(login_fd,26) = strlen(memo);
2227        if (strlen(memo) > 0)
2228                memcpy(WFIFOP(login_fd,28), memo, strlen(memo));
2229        WFIFOSET(login_fd,28+strlen(memo));
2230        bytes_to_read = 1;
2231
2232        return 0;
2233}
2234
2235//-----------------------------------------------
2236// Sub-function: Asking to obtain an account name
2237//-----------------------------------------------
2238int nameaccount(int id)
2239{
2240        WFIFOHEAD(login_fd,6);
2241        if (id < 0) {
2242                if (defaultlanguage == 'F') {
2243                        ShowMessage("Entrez un id ayant une valeur positive svp.\n");
2244                        ladmin_log("Id négatif donné pour rechecher le nom d'un compte (commande 'name').\n");
2245                } else {
2246                        ShowMessage("Please input a positive value for the id.\n");
2247                        ladmin_log("Negativ id given to search an account name ('name' command).\n");
2248                }
2249                return 136;
2250        }
2251
2252        if (defaultlanguage == 'F')
2253                ladmin_log("Envoi d'un requête au serveur de logins pour connaître le nom d'un compte.\n");
2254        else
2255                ladmin_log("Request to login-server to know an account name.\n");
2256
2257        WFIFOW(login_fd,0) = 0x7946;
2258        WFIFOL(login_fd,2) = id;
2259        WFIFOSET(login_fd,6);
2260        bytes_to_read = 1;
2261
2262        return 0;
2263}
2264
2265//------------------------------------------
2266// Sub-function: Asking to modify a password
2267// (Note: never send back a password with login-server!! security of passwords)
2268//------------------------------------------
2269int changepasswd(char* param)
2270{
2271        char name[1023], password[1023];
2272        WFIFOHEAD(login_fd,50);
2273
2274        memset(name, '\0', sizeof(name));
2275        memset(password, '\0', sizeof(password));
2276
2277        if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 &&
2278            sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 &&
2279            sscanf(param, "%s %[^\r\n]", name, password) < 1) {
2280                if (defaultlanguage == 'F') {
2281                        ShowMessage("Entrez un nom de compte svp.\n");
2282                        ShowMessage("<exemple> passwd nomtest nouveaumotdepasse\n");
2283                        ladmin_log("Nombre incorrect de paramètres pour changer le mot d'un passe d'un compte (commande 'password').\n");
2284                } else {
2285                        ShowMessage("Please input an account name.\n");
2286                        ShowMessage("<example> passwd testname newpassword\n");
2287                        ladmin_log("Incomplete parameters to change the password of an account ('password' command).\n");
2288                }
2289                return 136;
2290        }
2291
2292        if (verify_accountname(name) == 0) {
2293                return 102;
2294        }
2295
2296        if (strlen(password) == 0) {
2297                if (typepasswd(password) == 0)
2298                        return 134;
2299        }
2300        if (verify_password(password) == 0)
2301                return 131;
2302
2303        if (defaultlanguage == 'F') {
2304                ladmin_log("Envoi d'un requête au serveur de logins pour changer un mot de passe.\n");
2305        } else {
2306                ladmin_log("Request to login-server to change a password.\n");
2307        }
2308
2309        WFIFOW(login_fd,0) = 0x7934;
2310        memcpy(WFIFOP(login_fd,2), name, 24);
2311        memcpy(WFIFOP(login_fd,26), password, 24);
2312        WFIFOSET(login_fd,50);
2313        bytes_to_read = 1;
2314
2315        return 0;
2316}
2317
2318//----------------------------------------------------------------------
2319// Sub-function: Request to login-server to reload GM configuration file
2320// this function have no answer
2321//----------------------------------------------------------------------
2322int reloadGM(void)
2323{
2324        WFIFOHEAD(login_fd,2);
2325        WFIFOW(login_fd,0) = 0x7955;
2326        WFIFOSET(login_fd,2);
2327        bytes_to_read = 0;
2328
2329        if (defaultlanguage == 'F') {
2330                ladmin_log("Demande de recharger le fichier de configuration des GM envoyée.\n");
2331                ShowMessage("Demande de recharger le fichier de configuration des GM envoyée.\n");
2332                ShowMessage("Vérifiez les comptes GM actuels (après rechargement):\n");
2333        } else {
2334                ladmin_log("Request to reload the GM configuration file sended.\n");
2335                ShowMessage("Request to reload the GM configuration file sended.\n");
2336                ShowMessage("Check the actual GM accounts (after reloading):\n");
2337        }
2338        listaccount(parameters, 1); // 1: to list only GM
2339
2340        return 180;
2341}
2342
2343//-----------------------------------------------------
2344// Sub-function: Asking to modify the sex of an account
2345//-----------------------------------------------------
2346int changesex(char* param)
2347{
2348        char name[1023], sex[1023];
2349        WFIFOHEAD(login_fd,27);
2350
2351        memset(name, '\0', sizeof(name));
2352        memset(sex, '\0', sizeof(sex));
2353
2354        if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, sex) < 2 &&
2355            sscanf(param, "'%[^']' %[^\r\n]", name, sex) < 2 &&
2356            sscanf(param, "%s %[^\r\n]", name, sex) < 2) {
2357                if (defaultlanguage == 'F') {
2358                        ShowMessage("Entrez un nom de compte et un sexe svp.\n");
2359                        ShowMessage("<exemple> sex nomtest Male\n");
2360                        ladmin_log("Nombre incorrect de paramètres pour changer le sexe d'un compte (commande 'sex').\n");
2361                } else {
2362                        ShowMessage("Please input an account name and a sex.\n");
2363                        ShowMessage("<example> sex testname Male\n");
2364                        ladmin_log("Incomplete parameters to change the sex of an account ('sex' command).\n");
2365                }
2366                return 136;
2367        }
2368
2369        if (verify_accountname(name) == 0) {
2370                return 102;
2371        }
2372
2373        sex[0] = TOUPPER(sex[0]);
2374        if (strchr("MF", sex[0]) == NULL) {
2375                if (defaultlanguage == 'F') {
2376                        ShowMessage("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
2377                        ladmin_log("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
2378                } else {
2379                        ShowMessage("Illegal gender [%s]. Please input M or F.\n", sex);
2380                        ladmin_log("Illegal gender [%s]. Please input M or F.\n", sex);
2381                }
2382                return 103;
2383        }
2384
2385        if (defaultlanguage == 'F') {
2386                ladmin_log("Envoi d'un requête au serveur de logins pour changer un sexe.\n");
2387        } else {
2388                ladmin_log("Request to login-server to change a sex.\n");
2389        }
2390
2391        WFIFOW(login_fd,0) = 0x793c;
2392        memcpy(WFIFOP(login_fd,2), name, 24);
2393        WFIFOB(login_fd,26) = sex[0];
2394        WFIFOSET(login_fd,27);
2395        bytes_to_read = 1;
2396
2397        return 0;
2398}
2399
2400//-------------------------------------------------------------------------
2401// Sub-function of sub-function changestate, blockaccount or unblockaccount
2402// Asking to modify the state of an account
2403//-------------------------------------------------------------------------
2404int changestatesub(char* name, int state, char* error_message7)
2405{
2406        char error_message[1023]; // need to use, because we can modify error_message7
2407        WFIFOHEAD(login_fd,50);
2408
2409        memset(error_message, '\0', sizeof(error_message));
2410        strncpy(error_message, error_message7, sizeof(error_message)-1);
2411
2412        if ((state < 0 || state > 9) && state != 100) { // Valid values: 0: ok, or value of the 0x006a packet + 1
2413                if (defaultlanguage == 'F') {
2414                        ShowMessage("Entrez une des statuts suivantes svp:\n");
2415                        ShowMessage("  0 = Compte ok             6 = Your Game's EXE file is not the latest version\n");
2416                } else {
2417                        ShowMessage("Please input one of these states:\n");
2418                        ShowMessage("  0 = Account ok            6 = Your Game's EXE file is not the latest version\n");
2419                }
2420                ShowMessage("  1 = Unregistered ID       7 = You are Prohibited to log in until + message\n");
2421                ShowMessage("  2 = Incorrect Password    8 = Server is jammed due to over populated\n");
2422                ShowMessage("  3 = This ID is expired    9 = No MSG\n");
2423                ShowMessage("  4 = Rejected from Server  100 = This ID has been totally erased\n");
2424                ShowMessage("  5 = You have been blocked by the GM Team\n");
2425                if (defaultlanguage == 'F') {
2426                        ShowMessage("<exemples> state nomtest 5\n");
2427                        ShowMessage("           state nomtest 7 fin de votre ban\n");
2428                        ShowMessage("           block <nom compte>\n");
2429                        ShowMessage("           unblock <nom compte>\n");
2430                        ladmin_log("Valeur incorrecte pour le statut d'un compte (commande 'state', 'block' ou 'unblock').\n");
2431                } else {
2432                        ShowMessage("<examples> state testname 5\n");
2433                        ShowMessage("           state testname 7 end of your ban\n");
2434                        ShowMessage("           block <account name>\n");
2435                        ShowMessage("           unblock <account name>\n");
2436                        ladmin_log("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n");
2437                }
2438                return 151;
2439        }
2440
2441        if (verify_accountname(name) == 0) {
2442                return 102;
2443        }
2444
2445        if (state != 7) {
2446                strcpy(error_message, "-");
2447        } else {
2448                if (strlen(error_message) < 1) {
2449                        if (defaultlanguage == 'F') {
2450                                ShowMessage("Message d'erreur trop court. Entrez un message de 1-19 caractères.\n");
2451                                ladmin_log("Message d'erreur trop court. Entrez un message de 1-19 caractères.\n");
2452                        } else {
2453                                ShowMessage("Error message is too short. Please input a message of 1-19 bytes.\n");
2454                                ladmin_log("Error message is too short. Please input a message of 1-19 bytes.\n");
2455                        }
2456                        return 102;
2457                }
2458                if (strlen(error_message) > 19) {
2459                        if (defaultlanguage == 'F') {
2460                                ShowMessage("Message d'erreur trop long. Entrez un message de 1-19 caractères.\n");
2461                                ladmin_log("Message d'erreur trop long. Entrez un message de 1-19 caractères.\n");
2462                        } else {
2463                                ShowMessage("Error message is too long. Please input a message of 1-19 bytes.\n");
2464                                ladmin_log("Error message is too long. Please input a message of 1-19 bytes.\n");
2465                        }
2466                        return 102;
2467                }
2468        }
2469
2470        if (defaultlanguage == 'F') {
2471                ladmin_log("Envoi d'un requête au serveur de logins pour changer un statut.\n");
2472        } else {
2473                ladmin_log("Request to login-server to change a state.\n");
2474        }
2475
2476        WFIFOW(login_fd,0) = 0x7936;
2477        memcpy(WFIFOP(login_fd,2), name, 24);
2478        WFIFOL(login_fd,26) = state;
2479        memcpy(WFIFOP(login_fd,30), error_message, 20);
2480        WFIFOSET(login_fd,50);
2481        bytes_to_read = 1;
2482
2483        return 0;
2484}
2485
2486//-------------------------------------------------------
2487// Sub-function: Asking to modify the state of an account
2488//-------------------------------------------------------
2489int changestate(char* param)
2490{
2491        char name[1023], error_message[1023];
2492        int state;
2493
2494        memset(name, '\0', sizeof(name));
2495        memset(error_message, '\0', sizeof(error_message));
2496
2497        if (sscanf(param, "\"%[^\"]\" %d %[^\r\n]", name, &state, error_message) < 2 &&
2498            sscanf(param, "'%[^']' %d %[^\r\n]", name, &state, error_message) < 2 &&
2499            sscanf(param, "%s %d %[^\r\n]", name, &state, error_message) < 2) {
2500                if (defaultlanguage == 'F') {
2501                        ShowMessage("Entrez un nom de compte et un statut svp.\n");
2502                        ShowMessage("<exemples> state nomtest 5\n");
2503                        ShowMessage("           state nomtest 7 fin de votre ban\n");
2504                        ShowMessage("           block <nom compte>\n");
2505                        ShowMessage("           unblock <nom compte>\n");
2506                        ladmin_log("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'state').\n");
2507                } else {
2508                        ShowMessage("Please input an account name and a state.\n");
2509                        ShowMessage("<examples> state testname 5\n");
2510                        ShowMessage("           state testname 7 end of your ban\n");
2511                        ShowMessage("           block <account name>\n");
2512                        ShowMessage("           unblock <account name>\n");
2513                        ladmin_log("Incomplete parameters to change the state of an account ('state' command).\n");
2514                }
2515                return 136;
2516        }
2517
2518        return changestatesub(name, state, error_message);
2519}
2520
2521//-------------------------------------------
2522// Sub-function: Asking to unblock an account
2523//-------------------------------------------
2524int unblockaccount(char* param)
2525{
2526        char name[1023];
2527
2528        memset(name, '\0', sizeof(name));
2529
2530        if (strlen(param) == 0 ||
2531            (sscanf(param, "\"%[^\"]\"", name) < 1 &&
2532             sscanf(param, "'%[^']'", name) < 1 &&
2533             sscanf(param, "%[^\r\n]", name) < 1) ||
2534             strlen(name) == 0) {
2535                if (defaultlanguage == 'F') {
2536                        ShowMessage("Entrez un nom de compte svp.\n");
2537                        ShowMessage("<exemples> state nomtest 5\n");
2538                        ShowMessage("           state nomtest 7 fin de votre ban\n");
2539                        ShowMessage("           block <nom compte>\n");
2540                        ShowMessage("           unblock <nom compte>\n");
2541                        ladmin_log("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'unblock').\n");
2542                } else {
2543                        ShowMessage("Please input an account name.\n");
2544                        ShowMessage("<examples> state testname 5\n");
2545                        ShowMessage("           state testname 7 end of your ban\n");
2546                        ShowMessage("           block <account name>\n");
2547                        ShowMessage("           unblock <account name>\n");
2548                        ladmin_log("Incomplete parameters to change the state of an account ('unblock' command).\n");
2549                }
2550                return 136;
2551        }
2552
2553        return changestatesub(name, 0, "-"); // state 0, no error message
2554}
2555
2556//-------------------------------------------
2557// Sub-function: Asking to unblock an account
2558//-------------------------------------------
2559int blockaccount(char* param)
2560{
2561        char name[1023];
2562
2563        memset(name, '\0', sizeof(name));
2564
2565        if (strlen(param) == 0 ||
2566            (sscanf(param, "\"%[^\"]\"", name) < 1 &&
2567             sscanf(param, "'%[^']'", name) < 1 &&
2568             sscanf(param, "%[^\r\n]", name) < 1) ||
2569             strlen(name) == 0) {
2570                if (defaultlanguage == 'F') {
2571                        ShowMessage("Entrez un nom de compte svp.\n");
2572                        ShowMessage("<exemples> state nomtest 5\n");
2573                        ShowMessage("           state nomtest 7 fin de votre ban\n");
2574                        ShowMessage("           block <nom compte>\n");
2575                        ShowMessage("           unblock <nom compte>\n");
2576                        ladmin_log("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'block').\n");
2577                } else {
2578                        ShowMessage("Please input an account name.\n");
2579                        ShowMessage("<examples> state testname 5\n");
2580                        ShowMessage("           state testname 7 end of your ban\n");
2581                        ShowMessage("           block <account name>\n");
2582                        ShowMessage("           unblock <account name>\n");
2583                        ladmin_log("Incomplete parameters to change the state of an account ('block' command).\n");
2584                }
2585                return 136;
2586        }
2587
2588        return changestatesub(name, 5, "-"); // state 5, no error message
2589}
2590
2591//---------------------------------------------------------------------
2592// Sub-function: Add/substract time to the validity limit of an account
2593//---------------------------------------------------------------------
2594int timeaddaccount(char* param)
2595{
2596        char name[1023], modif[1023];
2597        int year, month, day, hour, minute, second;
2598        char * p_modif;
2599        int value, i;
2600        WFIFOHEAD(login_fd,38);
2601
2602        memset(name, '\0', sizeof(name));
2603        memset(modif, '\0', sizeof(modif));
2604        year = month = day = hour = minute = second = 0;
2605
2606        if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
2607            sscanf(param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
2608            sscanf(param, "%s %[^\r\n]", name, modif) < 2) {
2609                if (defaultlanguage == 'F') {
2610                        ShowMessage("Entrez un nom de compte et un modificateur svp.\n");
2611                        ShowMessage("  <exemple> timeadd nomtest +1m-2mn1s-6y\n");
2612                        ShowMessage("            Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n");
2613                        ShowMessage("            et 6 ans dans le même temps.\n");
2614                        ladmin_log("Nombre incorrect de paramètres pour modifier une date limite d'utilisation (commande 'timeadd').\n");
2615                } else {
2616                        ShowMessage("Please input an account name and a modifier.\n");
2617                        ShowMessage("  <example>: timeadd testname +1m-2mn1s-6y\n");
2618                        ShowMessage("             this example adds 1 month and 1 second, and substracts 2 minutes\n");
2619                        ShowMessage("             and 6 years at the same time.\n");
2620                        ladmin_log("Incomplete parameters to modify a limit time ('timeadd' command).\n");
2621                }
2622                return 136;
2623        }
2624        if (verify_accountname(name) == 0) {
2625                return 102;
2626        }
2627
2628        // lowercase for modif
2629        for (i = 0; modif[i]; i++)
2630                modif[i] = TOLOWER(modif[i]);
2631        p_modif = modif;
2632        while (strlen(p_modif) > 0) {
2633                value = atoi(p_modif);
2634                if (value == 0) {
2635                        p_modif++;
2636                } else {
2637                        if (p_modif[0] == '-' || p_modif[0] == '+')
2638                                p_modif++;
2639                        while (strlen(p_modif) > 0 && p_modif[0] >= '0' && p_modif[0] <= '9') {
2640                                p_modif++;
2641                        }
2642                        if (p_modif[0] == 's') {
2643                                second = value;
2644                                p_modif++;
2645                        } else if (p_modif[0] == 'm' && p_modif[1] == 'n') {
2646                                minute = value;
2647                                p_modif += 2;
2648                        } else if (p_modif[0] == 'h') {
2649                                hour = value;
2650                                p_modif++;
2651                        } else if (p_modif[0] == 'd' || p_modif[0] == 'j') {
2652                                day = value;
2653                                p_modif += 2;
2654                        } else if (p_modif[0] == 'm') {
2655                                month = value;
2656                                p_modif++;
2657                        } else if (p_modif[0] == 'y' || p_modif[0] == 'a') {
2658                                year = value;
2659                                p_modif++;
2660                        } else {
2661                                p_modif++;
2662                        }
2663                }
2664        }
2665
2666        if (defaultlanguage == 'F') {
2667                ShowMessage(" année:   %d\n", year);
2668                ShowMessage(" mois:    %d\n", month);
2669                ShowMessage(" jour:    %d\n", day);
2670                ShowMessage(" heure:   %d\n", hour);
2671                ShowMessage(" minute:  %d\n", minute);
2672                ShowMessage(" seconde: %d\n", second);
2673        } else {
2674                ShowMessage(" year:   %d\n", year);
2675                ShowMessage(" month:  %d\n", month);
2676                ShowMessage(" day:    %d\n", day);
2677                ShowMessage(" hour:   %d\n", hour);
2678                ShowMessage(" minute: %d\n", minute);
2679                ShowMessage(" second: %d\n", second);
2680        }
2681
2682        if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0) {
2683                if (defaultlanguage == 'F') {
2684                        ShowMessage("Vous devez entrer un ajustement avec cette commande, svp:\n");
2685                        ShowMessage("  Valeur d'ajustement (-1, 1, +1, etc...)\n");
2686                        ShowMessage("  Elément modifié:\n");
2687                        ShowMessage("    a ou y: année\n");
2688                        ShowMessage("    m:      mois\n");
2689                        ShowMessage("    j ou d: jour\n");
2690                        ShowMessage("    h:      heure\n");
2691                        ShowMessage("    mn:     minute\n");
2692                        ShowMessage("    s:      seconde\n");
2693                        ShowMessage("  <exemple> timeadd nomtest +1m-2mn1s-6y\n");
2694                        ShowMessage("            Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n");
2695                        ShowMessage("            et 6 ans dans le même temps.\n");
2696                        ladmin_log("Aucun ajustement n'est pas un ajustement (commande 'timeadd').\n");
2697                } else {
2698                        ShowMessage("Please give an adjustment with this command:\n");
2699                        ShowMessage("  Adjustment value (-1, 1, +1, etc...)\n");
2700                        ShowMessage("  Modified element:\n");
2701                        ShowMessage("    a or y: year\n");
2702                        ShowMessage("    m:      month\n");
2703                        ShowMessage("    j or d: day\n");
2704                        ShowMessage("    h:      hour\n");
2705                        ShowMessage("    mn:     minute\n");
2706                        ShowMessage("    s:      second\n");
2707                        ShowMessage("  <example> timeadd testname +1m-2mn1s-6y\n");
2708                        ShowMessage("            this example adds 1 month and 1 second, and substracts 2 minutes\n");
2709                        ShowMessage("            and 6 years at the same time.\n");
2710                        ladmin_log("No adjustment isn't an adjustment ('timeadd' command).\n");
2711                }
2712                return 137;
2713        }
2714        if (year > 127 || year < -127) {
2715                if (defaultlanguage == 'F') {
2716                        ShowMessage("Entrez un ajustement d'années correct (de -127 à 127), svp.\n");
2717                        ladmin_log("Ajustement de l'année hors norme ('timeadd' command).\n");
2718                } else {
2719                        ShowMessage("Please give a correct adjustment for the years (from -127 to 127).\n");
2720                        ladmin_log("Abnormal adjustment for the year ('timeadd' command).\n");
2721                }
2722                return 137;
2723        }
2724        if (month > 255 || month < -255) {
2725                if (defaultlanguage == 'F') {
2726                        ShowMessage("Entrez un ajustement de mois correct (de -255 à 255), svp.\n");
2727                        ladmin_log("Ajustement du mois hors norme ('timeadd' command).\n");
2728                } else {
2729                        ShowMessage("Please give a correct adjustment for the months (from -255 to 255).\n");
2730                        ladmin_log("Abnormal adjustment for the month ('timeadd' command).\n");
2731                }
2732                return 137;
2733        }
2734        if (day > 32767 || day < -32767) {
2735                if (defaultlanguage == 'F') {
2736                        ShowMessage("Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n");
2737                        ladmin_log("Ajustement des jours hors norme ('timeadd' command).\n");
2738                } else {
2739                        ShowMessage("Please give a correct adjustment for the days (from -32767 to 32767).\n");
2740                        ladmin_log("Abnormal adjustment for the days ('timeadd' command).\n");
2741                }
2742                return 137;
2743        }
2744        if (hour > 32767 || hour < -32767) {
2745                if (defaultlanguage == 'F') {
2746                        ShowMessage("Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n");
2747                        ladmin_log("Ajustement des heures hors norme ('timeadd' command).\n");
2748                } else {
2749                        ShowMessage("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
2750                        ladmin_log("Abnormal adjustment for the hours ('timeadd' command).\n");
2751                }
2752                return 137;
2753        }
2754        if (minute > 32767 || minute < -32767) {
2755                if (defaultlanguage == 'F') {
2756                        ShowMessage("Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n");
2757                        ladmin_log("Ajustement des minutes hors norme ('timeadd' command).\n");
2758                } else {
2759                        ShowMessage("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
2760                        ladmin_log("Abnormal adjustment for the minutes ('timeadd' command).\n");
2761                }
2762                return 137;
2763        }
2764        if (second > 32767 || second < -32767) {
2765                if (defaultlanguage == 'F') {
2766                        ShowMessage("Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n");
2767                        ladmin_log("Ajustement des secondes hors norme ('timeadd' command).\n");
2768                } else {
2769                        ShowMessage("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
2770                        ladmin_log("Abnormal adjustment for the seconds ('timeadd' command).\n");
2771                }
2772                return 137;
2773        }
2774
2775        if (defaultlanguage == 'F') {
2776                ladmin_log("Envoi d'un requête au serveur de logins pour modifier une date limite d'utilisation.\n");
2777        } else {
2778                ladmin_log("Request to login-server to modify a time limit.\n");
2779        }
2780
2781        WFIFOW(login_fd,0) = 0x7950;
2782        memcpy(WFIFOP(login_fd,2), name, 24);
2783        WFIFOW(login_fd,26) = (short)year;
2784        WFIFOW(login_fd,28) = (short)month;
2785        WFIFOW(login_fd,30) = (short)day;
2786        WFIFOW(login_fd,32) = (short)hour;
2787        WFIFOW(login_fd,34) = (short)minute;
2788        WFIFOW(login_fd,36) = (short)second;
2789        WFIFOSET(login_fd,38);
2790        bytes_to_read = 1;
2791
2792        return 0;
2793}
2794
2795//-------------------------------------------------
2796// Sub-function: Set a validity limit of an account
2797//-------------------------------------------------
2798int timesetaccount(char* param)
2799{
2800        char name[1023], date[1023], time[1023];
2801        int year, month, day, hour, minute, second;
2802        time_t expiration_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
2803        struct tm *tmtime;
2804        WFIFOHEAD(login_fd,30);
2805
2806        memset(name, '\0', sizeof(name));
2807        memset(date, '\0', sizeof(date));
2808        memset(time, '\0', sizeof(time));
2809        year = month = day = hour = minute = second = 0;
2810        expiration_time = 0;
2811        tmtime = localtime(&expiration_time); // initialize
2812
2813        if (sscanf(param, "\"%[^\"]\" %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
2814            sscanf(param, "'%[^']' %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
2815            sscanf(param, "%s %s %[^\r\n]", name, date, time) < 2) { // if date = 0, time can be void
2816                if (defaultlanguage == 'F') {
2817                        ShowMessage("Entrez un nom de compte, une date et une heure svp.\n");
2818                        ShowMessage("<exemple>: timeset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
2819                        ShowMessage("           timeset <nom_du_compte> 0    (0 = illimité)\n");
2820                        ShowMessage("           Heure par défaut [hh:mm:ss]: 23:59:59.\n");
2821                        ladmin_log("Nombre incorrect de paramètres pour fixer une date limite d'utilisation (commande 'timeset').\n");
2822                } else {
2823                        ShowMessage("Please input an account name, a date and a hour.\n");
2824                        ShowMessage("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
2825                        ShowMessage("           timeset <account_name> 0   (0 = unlimited)\n");
2826                        ShowMessage("           Default time [hh:mm:ss]: 23:59:59.\n");
2827                        ladmin_log("Incomplete parameters to set a limit time ('timeset' command).\n");
2828                }
2829                return 136;
2830        }
2831        if (verify_accountname(name) == 0) {
2832                return 102;
2833        }
2834
2835        if (time[0] == '\0')
2836                strcpy(time, "23:59:59");
2837
2838        if (atoi(date) != 0 &&
2839            ((sscanf(date, "%d/%d/%d", &year, &month, &day) < 3 &&
2840              sscanf(date, "%d-%d-%d", &year, &month, &day) < 3 &&
2841              sscanf(date, "%d.%d.%d", &year, &month, &day) < 3 &&
2842              sscanf(date, "%d'%d'%d", &year, &month, &day) < 3) ||
2843             sscanf(time, "%d:%d:%d", &hour, &minute, &second) < 3)) {
2844                if (defaultlanguage == 'F') {
2845                        ShowMessage("Entrez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n");
2846                        ladmin_log("Format incorrect pour la date/heure ('timeset' command).\n");
2847                } else {
2848                        ShowMessage("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
2849                        ladmin_log("Invalid format for the date/time ('timeset' command).\n");
2850                }
2851                return 102;
2852        }
2853
2854        if (atoi(date) == 0) {
2855                expiration_time = 0;
2856        } else {
2857                if (year < 70) {
2858                        year = year + 100;
2859                }
2860                if (year >= 1900) {
2861                        year = year - 1900;
2862                }
2863                if (month < 1 || month > 12) {
2864                        if (defaultlanguage == 'F') {
2865                                ShowMessage("Entrez un mois correct svp (entre 1 et 12).\n");
2866                                ladmin_log("Mois incorrect pour la date ('timeset' command).\n");
2867                        } else {
2868                                ShowMessage("Please give a correct value for the month (from 1 to 12).\n");
2869                                ladmin_log("Invalid month for the date ('timeset' command).\n");
2870                        }
2871                        return 102;
2872                }
2873                month = month - 1;
2874                if (day < 1 || day > 31) {
2875                        if (defaultlanguage == 'F') {
2876                                ShowMessage("Entrez un jour correct svp (entre 1 et 31).\n");
2877                                ladmin_log("Jour incorrect pour la date ('timeset' command).\n");
2878                        } else {
2879                                ShowMessage("Please give a correct value for the day (from 1 to 31).\n");
2880                                ladmin_log("Invalid day for the date ('timeset' command).\n");
2881                        }
2882                        return 102;
2883                }
2884                if (((month == 3 || month == 5 || month == 8 || month == 10) && day > 30) ||
2885                    (month == 1 && day > 29)) {
2886                        if (defaultlanguage == 'F') {
2887                                ShowMessage("Entrez un jour correct en fonction du mois (%d) svp.\n", month);
2888                                ladmin_log("Jour incorrect pour ce mois correspondant ('timeset' command).\n");
2889                        } else {
2890                                ShowMessage("Please give a correct value for a day of this month (%d).\n", month);
2891                                ladmin_log("Invalid day for this month ('timeset' command).\n");
2892                        }
2893                        return 102;
2894                }
2895                if (hour < 0 || hour > 23) {
2896                        if (defaultlanguage == 'F') {
2897                                ShowMessage("Entrez une heure correcte svp (entre 0 et 23).\n");
2898                                ladmin_log("Heure incorrecte pour l'heure ('timeset' command).\n");
2899                        } else {
2900                                ShowMessage("Please give a correct value for the hour (from 0 to 23).\n");
2901                                ladmin_log("Invalid hour for the time ('timeset' command).\n");
2902                        }
2903                        return 102;
2904                }
2905                if (minute < 0 || minute > 59) {
2906                        if (defaultlanguage == 'F') {
2907                                ShowMessage("Entrez des minutes correctes svp (entre 0 et 59).\n");
2908                                ladmin_log("Minute incorrecte pour l'heure ('timeset' command).\n");
2909                        } else {
2910                                ShowMessage("Please give a correct value for the minutes (from 0 to 59).\n");
2911                                ladmin_log("Invalid minute for the time ('timeset' command).\n");
2912                        }
2913                        return 102;
2914                }
2915                if (second < 0 || second > 59) {
2916                        if (defaultlanguage == 'F') {
2917                                ShowMessage("Entrez des secondes correctes svp (entre 0 et 59).\n");
2918                                ladmin_log("Seconde incorrecte pour l'heure ('timeset' command).\n");
2919                        } else {
2920                                ShowMessage("Please give a correct value for the seconds (from 0 to 59).\n");
2921                                ladmin_log("Invalid second for the time ('timeset' command).\n");
2922                        }
2923                        return 102;
2924                }
2925                tmtime->tm_year = year;
2926                tmtime->tm_mon = month;
2927                tmtime->tm_mday = day;
2928                tmtime->tm_hour = hour;
2929                tmtime->tm_min = minute;
2930                tmtime->tm_sec = second;
2931                tmtime->tm_isdst = -1; // -1: no winter/summer time modification
2932                expiration_time = mktime(tmtime);
2933                if (expiration_time == -1) {
2934                        if (defaultlanguage == 'F') {
2935                                ShowMessage("Date incorrecte.\n");
2936                                ShowMessage("Ajoutez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n");
2937                                ladmin_log("Date incorrecte. ('timeset' command).\n");
2938                        } else {
2939                                ShowMessage("Invalid date.\n");
2940                                ShowMessage("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
2941                                ladmin_log("Invalid date. ('timeset' command).\n");
2942                        }
2943                        return 102;
2944                }
2945        }
2946
2947        if (defaultlanguage == 'F') {
2948                ladmin_log("Envoi d'un requête au serveur de logins pour fixer une date limite d'utilisation.\n");
2949        } else {
2950                ladmin_log("Request to login-server to set a time limit.\n");
2951        }
2952
2953        WFIFOW(login_fd,0) = 0x7948;
2954        memcpy(WFIFOP(login_fd,2), name, 24);
2955        WFIFOL(login_fd,26) = (int)expiration_time;
2956        WFIFOSET(login_fd,30);
2957        bytes_to_read = 1;
2958
2959        return 0;
2960}
2961
2962//------------------------------------------------------------------------------
2963// Sub-function: Asking to displaying information about an account (by its name)
2964//------------------------------------------------------------------------------
2965int whoaccount(char* param)
2966{
2967        char name[1023];
2968        WFIFOHEAD(login_fd,26);
2969
2970        memset(name, '\0', sizeof(name));
2971
2972        if (strlen(param) == 0 ||
2973            (sscanf(param, "\"%[^\"]\"", name) < 1 &&
2974             sscanf(param, "'%[^']'", name) < 1 &&
2975             sscanf(param, "%[^\r\n]", name) < 1) ||
2976             strlen(name) == 0) {
2977                if (defaultlanguage == 'F') {
2978                        ShowMessage("Entrez un nom de compte svp.\n");
2979                        ShowMessage("<exemple> who nomtest\n");
2980                        ladmin_log("Aucun nom n'a été donné pour trouver le compte.\n");
2981                } else {
2982                        ShowMessage("Please input an account name.\n");
2983                        ShowMessage("<example> who testname\n");
2984                        ladmin_log("No name was given to found the account.\n");
2985                }
2986                return 136;
2987        }
2988        if (verify_accountname(name) == 0) {
2989                return 102;
2990        }
2991
2992        if (defaultlanguage == 'F') {
2993                ladmin_log("Envoi d'un requête au serveur de logins pour obtenir le information d'un compte (par le nom).\n");
2994        } else {
2995                ladmin_log("Request to login-server to obtain information about an account (by its name).\n");
2996        }
2997
2998        WFIFOW(login_fd,0) = 0x7952;
2999        memcpy(WFIFOP(login_fd,2), name, 24);
3000        WFIFOSET(login_fd,26);
3001        bytes_to_read = 1;
3002
3003        return 0;
3004}
3005
3006//--------------------------------------------------------
3007// Sub-function: Asking of the version of the login-server
3008//--------------------------------------------------------
3009int checkloginversion(void)
3010{
3011        WFIFOHEAD(login_fd,2);
3012        if (defaultlanguage == 'F')
3013                ladmin_log("Envoi d'un requête au serveur de logins pour obtenir sa version.\n");
3014        else
3015                ladmin_log("Request to login-server to obtain its version.\n");
3016
3017        WFIFOW(login_fd,0) = 0x7530;
3018        WFIFOSET(login_fd,2);
3019        bytes_to_read = 1;
3020
3021        return 0;
3022}
3023
3024//---------------------------------------------
3025// Prompt function
3026// this function wait until user type a command
3027// and analyse the command.
3028//---------------------------------------------
3029int prompt(void)
3030{
3031        int i, j;
3032        char buf[1024];
3033        char *p;
3034
3035        // while we don't wait new packets
3036        while (bytes_to_read == 0) {
3037                // for help with the console colors look here:
3038                // http://www.edoceo.com/liberum/?doc=printf-with-color
3039                // some code explanation (used here):
3040                // \033[2J : clear screen and go up/left (0, 0 position)
3041                // \033[K  : clear line from actual position to end of the line
3042                // \033[0m : reset color parameter
3043                // \033[1m : use bold for font
3044                ShowMessage("\n");
3045                if (defaultlanguage == 'F')
3046                        ShowMessage("\033[32mPour afficher les commandes, tapez 'Entrée'.\033[0m\n");
3047                else
3048                        ShowMessage("\033[32mTo list the commands, type 'enter'.\033[0m\n");
3049                ShowMessage("\033[0;36mLadmin-> \033[0m");
3050                ShowMessage("\033[1m");
3051                fflush(stdout);
3052
3053                // get command and parameter
3054                memset(buf, '\0', sizeof(buf));
3055                fflush(stdin);
3056                fgets(buf, sizeof(buf), stdin);
3057
3058                ShowMessage("\033[0m");
3059                fflush(stdout);
3060
3061                // remove final \n
3062                if((p = strrchr(buf, '\n')) != NULL)
3063                        p[0] = '\0';
3064                // remove all control char
3065                for (i = 0; buf[i]; i++)
3066                        if (buf[i] < 32) {
3067                                // remove cursor control.
3068                                if (buf[i] == 27 && buf[i+1] == '[' &&
3069                                    (buf[i+2] == 'H' || // home position (cursor)
3070                                     buf[i+2] == 'J' || // clear screen
3071                                     buf[i+2] == 'A' || // up 1 line
3072                                     buf[i+2] == 'B' || // down 1 line
3073                                     buf[i+2] == 'C' || // right 1 position
3074                                     buf[i+2] == 'D' || // left 1 position
3075                                     buf[i+2] == 'G')) { // center cursor (windows)
3076                                        for (j = i; buf[j]; j++)
3077                                                buf[j] = buf[j+3];
3078                                } else if (buf[i] == 27 && buf[i+1] == '[' && buf[i+2] == '2' && buf[i+3] == 'J') { // clear screen
3079                                        for (j = i; buf[j]; j++)
3080                                                buf[j] = buf[j+4];
3081                                } else if (buf[i] == 27 && buf[i+1] == '[' && buf[i+3] == '~' &&
3082                                           (buf[i+2] == '1' || // home (windows)
3083                                            buf[i+2] == '2' || // insert (windows)
3084                                            buf[i+2] == '3' || // del (windows)
3085                                            buf[i+2] == '4' || // end (windows)
3086                                            buf[i+2] == '5' || // pgup (windows)
3087                                            buf[i+2] == '6')) { // pgdown (windows)
3088                                        for (j = i; buf[j]; j++)
3089                                                buf[j] = buf[j+4];
3090                                } else {
3091                                        // remove other control char.
3092                                        for (j = i; buf[j]; j++)
3093                                                buf[j] = buf[j+1];
3094                                }
3095                                i--;
3096                        }
3097
3098                // extract command name and parameters
3099                memset(command, '\0', sizeof(command));
3100                memset(parameters, '\0', sizeof(parameters));
3101                sscanf(buf, "%1023s %[^\n]", command, parameters);
3102                command[1023] = '\0';
3103                parameters[1023] = '\0';
3104
3105                // lowercase for command line
3106                for (i = 0; command[i]; i++)
3107                        command[i] = TOLOWER(command[i]);
3108
3109                if (command[0] == '?' || strlen(command) == 0) {
3110                        if (defaultlanguage == 'F') {
3111                                strcpy(buf, "aide");
3112                                strcpy(command, "aide");
3113                        } else {
3114                                strcpy(buf, "help");
3115                                strcpy(command, "help");
3116                        }
3117                }
3118
3119                // Analyse of the command
3120                check_command(command); // give complete name to the command
3121
3122                if (strlen(parameters) == 0) {
3123                        if (defaultlanguage == 'F') {
3124                                ladmin_log("Commande: '%s' (sans paramètre)\n", command, parameters);
3125                        } else {
3126                                ladmin_log("Command: '%s' (without parameters)\n", command, parameters);
3127                        }
3128                } else {
3129                        if (defaultlanguage == 'F') {
3130                                ladmin_log("Commande: '%s', paramètres: '%s'\n", command, parameters);
3131                        } else {
3132                                ladmin_log("Command: '%s', parameters: '%s'\n", command, parameters);
3133                        }
3134                }
3135
3136                // Analyse of the command
3137// help
3138                if (strcmp(command, "aide") == 0) {
3139                        display_help(parameters, 1); // 1: french
3140                } else if (strcmp(command, "help") == 0 ) {
3141                        display_help(parameters, 0); // 0: english
3142// general commands
3143                } else if (strcmp(command, "add") == 0) {
3144                        addaccount(parameters, 0); // 0: no email
3145                } else if (strcmp(command, "ban") == 0) {
3146                        banaccount(parameters);
3147                } else if (strcmp(command, "banadd") == 0) {
3148                        banaddaccount(parameters);
3149                } else if (strcmp(command, "banset") == 0) {
3150                        bansetaccount(parameters);
3151                } else if (strcmp(command, "block") == 0) {
3152                        blockaccount(parameters);
3153                } else if (strcmp(command, "check") == 0) {
3154                        checkaccount(parameters);
3155                } else if (strcmp(command, "create") == 0) {
3156                        addaccount(parameters, 1); // 1: with email
3157                } else if (strcmp(command, "delete") == 0) {
3158                        delaccount(parameters);
3159                } else if (strcmp(command, "email") == 0) {
3160                        changeemail(parameters);
3161                } else if (strcmp(command, "getcount") == 0) {
3162                        getlogincount();
3163                } else if (strcmp(command, "gm") == 0) {
3164                        changegmlevel(parameters);
3165                } else if (strcmp(command, "id") == 0) {
3166                        idaccount(parameters);
3167                } else if (strcmp(command, "info") == 0) {
3168                        infoaccount(atoi(parameters));
3169                } else if (strcmp(command, "kami") == 0) {
3170                        sendbroadcast(0, parameters); // flag for normal
3171                } else if (strcmp(command, "kamib") == 0) {
3172                        sendbroadcast(0x10, parameters); // flag for blue
3173                } else if (strcmp(command, "language") == 0) {
3174                        changelanguage(parameters);
3175                } else if (strcmp(command, "list") == 0) {
3176                        listaccount(parameters, 0); // 0: to list all
3177                } else if (strcmp(command, "listban") == 0) {
3178                        listaccount(parameters, 3); // 3: to list only accounts with state or bannished
3179                } else if (strcmp(command, "listgm") == 0) {
3180                        listaccount(parameters, 1); // 1: to list only GM
3181                } else if (strcmp(command, "listok") == 0) {
3182                        listaccount(parameters, 4); // 4: to list only accounts without state and not bannished
3183                } else if (strcmp(command, "memo") == 0) {
3184                        changememo(parameters);
3185                } else if (strcmp(command, "name") == 0) {
3186                        nameaccount(atoi(parameters));
3187                } else if (strcmp(command, "password") == 0) {
3188                        changepasswd(parameters);
3189                } else if (strcmp(command, "reloadgm") == 0) {
3190                        reloadGM();
3191                } else if (strcmp(command, "search") == 0) { // no regex in C version
3192                        listaccount(parameters, 2); // 2: to list with pattern
3193                } else if (strcmp(command, "sex") == 0) {
3194                        changesex(parameters);
3195                } else if (strcmp(command, "state") == 0) {
3196                        changestate(parameters);
3197                } else if (strcmp(command, "timeadd") == 0) {
3198                        timeaddaccount(parameters);
3199                } else if (strcmp(command, "timeset") == 0) {
3200                        timesetaccount(parameters);
3201                } else if (strcmp(command, "unban") == 0) {
3202                        unbanaccount(parameters);
3203                } else if (strcmp(command, "unblock") == 0) {
3204                        unblockaccount(parameters);
3205                } else if (strcmp(command, "version") == 0) {
3206                        checkloginversion();
3207                } else if (strcmp(command, "who") == 0) {
3208                        whoaccount(parameters);
3209// quit
3210                } else if (strcmp(command, "quit") == 0 ||
3211                           strcmp(command, "exit") == 0 ||
3212                           strcmp(command, "end") == 0) {
3213                        if (defaultlanguage == 'F') {
3214                                ShowMessage("Au revoir.\n");
3215                        } else {
3216                                ShowMessage("Bye.\n");
3217                        }
3218                        exit(EXIT_SUCCESS);
3219// unknown command
3220                } else {
3221                        if (defaultlanguage == 'F') {
3222                                ShowMessage("Commande inconnue [%s].\n", buf);
3223                                ladmin_log("Commande inconnue [%s].\n", buf);
3224                        } else {
3225                                ShowMessage("Unknown command [%s].\n", buf);
3226                                ladmin_log("Unknown command [%s].\n", buf);
3227                        }
3228                }
3229        }
3230
3231        return 0;
3232}
3233
3234//-------------------------------------------------------------
3235// Function: Parse receiving informations from the login-server
3236//-------------------------------------------------------------
3237int parse_fromlogin(int fd)
3238{
3239        struct char_session_data *sd;
3240        int id;
3241        RFIFOHEAD(fd);
3242        if (session[fd]->flag.eof) {
3243                if (defaultlanguage == 'F') {
3244                        ShowMessage("Impossible de se connecter au serveur de login [%s:%d] !\n", loginserverip, loginserverport);
3245                        ladmin_log("Impossible de se connecter au serveur de login [%s:%d] !\n", loginserverip, loginserverport);
3246                } else {
3247                        ShowMessage("Impossible to have a connection with the login-server [%s:%d] !\n", loginserverip, loginserverport);
3248                        ladmin_log("Impossible to have a connection with the login-server [%s:%d] !\n", loginserverip, loginserverport);
3249                }
3250                do_close(fd);
3251                exit(EXIT_FAILURE);
3252        }
3253
3254//      ShowMessage("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0));
3255        sd = (struct char_session_data*)session[fd]->session_data;
3256
3257        while(RFIFOREST(fd) >= 2) {
3258                switch(RFIFOW(fd,0)) {
3259                case 0x7919:    // answer of a connection request
3260                        if (RFIFOREST(fd) < 3)
3261                                return 0;
3262                        if (RFIFOB(fd,2) != 0) {
3263                                if (defaultlanguage == 'F') {
3264                                        ShowMessage("Erreur de login:\n");
3265                                        ShowMessage(" - mot de passe incorrect,\n");
3266                                        ShowMessage(" - système d'administration non activé, ou\n");
3267                                        ShowMessage(" - IP non autorisée.\n");
3268                                        ladmin_log("Erreur de login: mot de passe incorrect, système d'administration non activé, ou IP non autorisée.\n");
3269                                } else {
3270                                        ShowMessage("Error at login:\n");
3271                                        ShowMessage(" - incorrect password,\n");
3272                                        ShowMessage(" - administration system not activated, or\n");
3273                                        ShowMessage(" - unauthorised IP.\n");
3274                                        ladmin_log("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n");
3275                                }
3276                                set_eof(fd);
3277                                //bytes_to_read = 1; // not stop at prompt
3278                                return 0;
3279                        } else {
3280                                if (defaultlanguage == 'F') {
3281                                        ShowMessage("Connexion établie.\n");
3282                                        ladmin_log("Connexion établie.\n");
3283                                        ShowMessage("Lecture de la version du serveur de login...\n");
3284                                        ladmin_log("Lecture de la version du serveur de login...\n");
3285                                } else {
3286                                        ShowMessage("Established connection.\n");
3287                                        ladmin_log("Established connection.\n");
3288                                        ShowMessage("Reading of the version of the login-server...\n");
3289                                        ladmin_log("Reading of the version of the login-server...\n");
3290                                }
3291                                //bytes_to_read = 1; // unchanged
3292                                checkloginversion();
3293                        }
3294                        RFIFOSKIP(fd,3);
3295                        break;
3296
3297                case 0x01dc:    // answer of a coding key request
3298                        if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
3299                                return 0;
3300                  {
3301                        char md5str[64] = "", md5bin[32];
3302                        WFIFOHEAD(login_fd, 20);
3303                        if (passenc == 1) {
3304                                strncpy(md5str, (const char*)RFIFOP(fd,4), RFIFOW(fd,2) - 4);
3305                                strcat(md5str, loginserveradminpassword);
3306                        } else if (passenc == 2) {
3307                                strncpy(md5str, loginserveradminpassword, sizeof(loginserveradminpassword));
3308                                strcat(md5str, (const char*)RFIFOP(fd,4));
3309                        }
3310                        MD5_String2binary(md5str, md5bin);
3311                        WFIFOW(login_fd,0) = 0x7918; // Request for administation login (encrypted password)
3312                        WFIFOW(login_fd,2) = passenc; // Encrypted type
3313                        memcpy(WFIFOP(login_fd,4), md5bin, 16);
3314                        WFIFOSET(login_fd,20);
3315                        if (defaultlanguage == 'F') {
3316                                ShowMessage("Réception de la clef MD5.\n");
3317                                ladmin_log("Réception de la clef MD5.\n");
3318                                ShowMessage("Envoi du mot de passe crypté...\n");
3319                                ladmin_log("Envoi du mot de passe crypté...\n");
3320                        } else {
3321                                ShowMessage("Receiving of the MD5 key.\n");
3322                                ladmin_log("Receiving of the MD5 key.\n");
3323                                ShowMessage("Sending of the encrypted password...\n");
3324                                ladmin_log("Sending of the encrypted password...\n");
3325                        }
3326                  }
3327                        bytes_to_read = 1;
3328                        RFIFOSKIP(fd,RFIFOW(fd,2));
3329                        break;
3330
3331                case 0x7531:    // Displaying of the version of the login-server
3332                        if (RFIFOREST(fd) < 10)
3333                                return 0;
3334                        ShowMessage("  Login-Server [%s:%d]\n", loginserverip, loginserverport);
3335                        if (((int)RFIFOB(login_fd,5)) == 0) {
3336                                ShowMessage("  eAthena version stable-%d.%d", (int)RFIFOB(login_fd,2), (int)RFIFOB(login_fd,3));
3337                        } else {
3338                                ShowMessage("  eAthena version dev-%d.%d", (int)RFIFOB(login_fd,2), (int)RFIFOB(login_fd,3));
3339                        }
3340                        if (((int)RFIFOB(login_fd,4)) == 0)
3341                                ShowMessage(" revision %d", (int)RFIFOB(login_fd,4));
3342                        if (((int)RFIFOB(login_fd,6)) == 0)
3343                                ShowMessage("%d.\n", RFIFOW(login_fd,8));
3344                        else
3345                                ShowMessage("-mod%d.\n", RFIFOW(login_fd,8));
3346                        bytes_to_read = 0;
3347                        RFIFOSKIP(fd,10);
3348                        break;
3349
3350                case 0x7921:    // Displaying of the list of accounts
3351                        if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
3352                                return 0;
3353                        if (RFIFOW(fd,2) < 5) {
3354                                if (defaultlanguage == 'F') {
3355                                        ladmin_log("  Réception d'une liste des comptes vide.\n");
3356                                        if (list_count == 0)
3357                                                ShowMessage("Aucun compte trouvé.\n");
3358                                        else if (list_count == 1)
3359                                                ShowMessage("1 compte trouvé.\n");
3360                                        else
3361                                                ShowMessage("%d comptes trouvés.\n", list_count);
3362                                } else {
3363                                        ladmin_log("  Receiving of a void accounts list.\n");
3364                                        if (list_count == 0)
3365                                                ShowMessage("No account found.\n");
3366                                        else if (list_count == 1)
3367                                                ShowMessage("1 account found.\n");
3368                                        else
3369                                                ShowMessage("%d accounts found.\n", list_count);
3370                                }
3371                                bytes_to_read = 0;
3372                        } else {
3373                                int i;
3374                                WFIFOHEAD(login_fd,10);
3375                                if (defaultlanguage == 'F')
3376                                        ladmin_log("  Réception d'une liste des comptes.\n");
3377                                else
3378                                        ladmin_log("  Receiving of a accounts list.\n");
3379                                for(i = 4; i < RFIFOW(fd,2); i += 38) {
3380                                        int j;
3381                                        char userid[24];
3382                                        char lower_userid[24];
3383                                        memcpy(userid, RFIFOP(fd,i + 5), sizeof(userid));
3384                                        userid[sizeof(userid)-1] = '\0';
3385                                        memset(lower_userid, '\0', sizeof(lower_userid));
3386                                        for (j = 0; userid[j]; j++)
3387                                                lower_userid[j] = TOLOWER(userid[j]);
3388                                        list_first = RFIFOL(fd,i) + 1;
3389                                        // here are checks...
3390                                        if (list_type == 0 ||
3391                                            (list_type == 1 && RFIFOB(fd,i+4) > 0) ||
3392                                            (list_type == 2 && strstr(lower_userid, parameters) != NULL) ||
3393                                            (list_type == 3 && RFIFOL(fd,i+34) != 0) ||
3394                                            (list_type == 4 && RFIFOL(fd,i+34) == 0)) {
3395                                                ShowMessage("%10d ", (int)RFIFOL(fd,i));
3396                                                if (RFIFOB(fd,i+4) == 0)
3397                                                        ShowMessage("   ");
3398                                                else
3399                                                        ShowMessage("%2d ", (int)RFIFOB(fd,i+4));
3400                                                ShowMessage("%-24s", userid);
3401                                                if (defaultlanguage == 'F') {
3402                                                        if (RFIFOB(fd,i+29) == 0)
3403                                                                ShowMessage("%-5s ", "Femme");
3404                                                        else if (RFIFOB(fd,i+29) == 1)
3405                                                                ShowMessage("%-5s ", "Male");
3406                                                        else
3407                                                                ShowMessage("%-5s ", "Servr");
3408                                                } else {
3409                                                        if (RFIFOB(fd,i+29) == 0)
3410                                                                ShowMessage("%-5s ", "Femal");
3411                                                        else if (RFIFOB(fd,i+29) == 1)
3412                                                                ShowMessage("%-5s ", "Male");
3413                                                        else
3414                                                                ShowMessage("%-5s ", "Servr");
3415                                                }
3416                                                ShowMessage("%6d ", (int)RFIFOL(fd,i+30));
3417                                                switch(RFIFOL(fd,i+34)) {
3418                                                case 0:
3419                                                        if (defaultlanguage == 'F')
3420                                                                ShowMessage("%-27s\n", "Compte Ok");
3421                                                        else
3422                                                                ShowMessage("%-27s\n", "Account OK");
3423                                                        break;
3424                                                case 1:
3425                                                        ShowMessage("%-27s\n", "Unregistered ID");
3426                                                        break;
3427                                                case 2:
3428                                                        ShowMessage("%-27s\n", "Incorrect Password");
3429                                                        break;
3430                                                case 3:
3431                                                        ShowMessage("%-27s\n", "This ID is expired");
3432                                                        break;
3433                                                case 4:
3434                                                        ShowMessage("%-27s\n", "Rejected from Server");
3435                                                        break;
3436                                                case 5:
3437                                                        ShowMessage("%-27s\n", "Blocked by the GM Team"); // You have been blocked by the GM Team
3438                                                        break;
3439                                                case 6:
3440                                                        ShowMessage("%-27s\n", "Your EXE file is too old"); // Your Game's EXE file is not the latest version
3441                                                        break;
3442                                                case 7:
3443                                                        ShowMessage("%-27s\n", "Banishement or");
3444                                                        ShowMessage("                                                   Prohibited to login until...\n"); // You are Prohibited to log in until %s
3445                                                        break;
3446                                                case 8:
3447                                                        ShowMessage("%-27s\n", "Server is over populated");
3448                                                        break;
3449                                                case 9:
3450                                                        ShowMessage("%-27s\n", "No MSG");
3451                                                        break;
3452                                                default: // 100
3453                                                        ShowMessage("%-27s\n", "This ID is totally erased"); // This ID has been totally erased
3454                                                        break;
3455                                                }
3456                                                list_count++;
3457                                        }
3458                                }
3459                                // asking of the following acounts
3460                                if (defaultlanguage == 'F')
3461                                        ladmin_log("Envoi d'un requête au serveur de logins pour obtenir la liste des comptes de %d à %d (complément).\n", list_first, list_last);
3462                                else
3463                                        ladmin_log("Request to login-server to obtain the list of accounts from %d to %d (complement).\n", list_first, list_last);
3464                                WFIFOW(login_fd,0) = 0x7920;
3465                                WFIFOL(login_fd,2) = list_first;
3466                                WFIFOL(login_fd,6) = list_last;
3467                                WFIFOSET(login_fd,10);
3468                                bytes_to_read = 1;
3469                        }
3470                        RFIFOSKIP(fd,RFIFOW(fd,2));
3471                        break;
3472
3473                case 0x7931:    // Answer of login-server about an account creation
3474                        if (RFIFOREST(fd) < 30)
3475                                return 0;
3476                        id=RFIFOL(fd,2);
3477                        if (id == -1) {
3478                                if (defaultlanguage == 'F') {
3479                                        ShowMessage("Echec à la création du compte [%s]. Un compte identique existe déjà.\n", RFIFOP(fd,6));
3480                                        ladmin_log("Echec à la création du compte [%s]. Un compte identique existe déjà.\n", RFIFOP(fd,6));
3481                                } else {
3482                                        ShowMessage("Account [%s] creation failed. Same account already exists.\n", RFIFOP(fd,6));
3483                                        ladmin_log("Account [%s] creation failed. Same account already exists.\n", RFIFOP(fd,6));
3484                                }
3485                        } else {
3486                                if (defaultlanguage == 'F') {
3487                                        ShowMessage("Compte [%s] créé avec succès [id: %d].\n", RFIFOP(fd,6), id);
3488                                        ladmin_log("Compte [%s] créé avec succès [id: %d].\n", RFIFOP(fd,6), id);
3489                                } else {
3490                                        ShowMessage("Account [%s] is successfully created [id: %d].\n", RFIFOP(fd,6), id);
3491                                        ladmin_log("Account [%s] is successfully created [id: %d].\n", RFIFOP(fd,6), id);
3492                                }
3493                        }
3494                        bytes_to_read = 0;
3495                        RFIFOSKIP(fd,30);
3496                        break;
3497
3498                case 0x7933:    // Answer of login-server about an account deletion
3499                        if (RFIFOREST(fd) < 30)
3500                                return 0;
3501                        if (RFIFOL(fd,2) == -1) {
3502                                if (defaultlanguage == 'F') {
3503                                        ShowMessage("Echec de la suppression du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3504                                        ladmin_log("Echec de la suppression du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3505                                } else {
3506                                        ShowMessage("Account [%s] deletion failed. Account doesn't exist.\n", RFIFOP(fd,6));
3507                                        ladmin_log("Account [%s] deletion failed. Account doesn't exist.\n", RFIFOP(fd,6));
3508                                }
3509                        } else {
3510                                if (defaultlanguage == 'F') {
3511                                        ShowMessage("Compte [%s][id: %d] SUPPRIME avec succès.\n", RFIFOP(fd,6), (int)RFIFOL(fd,2));
3512                                        ladmin_log("Compte [%s][id: %d] SUPPRIME avec succès.\n", RFIFOP(fd,6), RFIFOL(fd,2));
3513                                } else {
3514                                        ShowMessage("Account [%s][id: %d] is successfully DELETED.\n", RFIFOP(fd,6), (int)RFIFOL(fd,2));
3515                                        ladmin_log("Account [%s][id: %d] is successfully DELETED.\n", RFIFOP(fd,6), RFIFOL(fd,2));
3516                                }
3517                        }
3518                        bytes_to_read = 0;
3519                        RFIFOSKIP(fd,30);
3520                        break;
3521
3522                case 0x7935:    // answer of the change of an account password
3523                        if (RFIFOREST(fd) < 30)
3524                                return 0;
3525                        if (RFIFOL(fd,2) == -1) {
3526                                if (defaultlanguage == 'F') {
3527                                        ShowMessage("Echec de la modification du mot de passe du compte [%s].\n", RFIFOP(fd,6));
3528                                        ShowMessage("Le compte [%s] n'existe pas.\n", RFIFOP(fd,6));
3529                                        ladmin_log("Echec de la modification du mot de passe du compte. Le compte [%s] n'existe pas.\n", RFIFOP(fd,6));
3530                                } else {
3531                                        ShowMessage("Account [%s] password changing failed.\n", RFIFOP(fd,6));
3532                                        ShowMessage("Account [%s] doesn't exist.\n", RFIFOP(fd,6));
3533                                        ladmin_log("Account password changing failed. The compte [%s] doesn't exist.\n", RFIFOP(fd,6));
3534                                }
3535                        } else {
3536                                if (defaultlanguage == 'F') {
3537                                        ShowMessage("Modification du mot de passe du compte [%s][id: %d] réussie.\n", RFIFOP(fd,6), (int)RFIFOL(fd,2));
3538                                        ladmin_log("Modification du mot de passe du compte [%s][id: %d] réussie.\n", RFIFOP(fd,6), (int)RFIFOL(fd,2));
3539                                } else {
3540                                        ShowMessage("Account [%s][id: %d] password successfully changed.\n", RFIFOP(fd,6), (int)RFIFOL(fd,2));
3541                                        ladmin_log("Account [%s][id: %d] password successfully changed.\n", RFIFOP(fd,6), (int)RFIFOL(fd,2));
3542                                }
3543                        }
3544                        bytes_to_read = 0;
3545                        RFIFOSKIP(fd,30);
3546                        break;
3547
3548                case 0x7937:    // answer of the change of an account state
3549                        if (RFIFOREST(fd) < 34)
3550                                return 0;
3551                        if (RFIFOL(fd,2) == -1) {
3552                                if (defaultlanguage == 'F') {
3553                                        ShowMessage("Echec du changement du statut du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3554                                        ladmin_log("Echec du changement du statut du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3555                                } else {
3556                                        ShowMessage("Account [%s] state changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3557                                        ladmin_log("Account [%s] state changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3558                                }
3559                        } else {
3560                                char tmpstr[256];
3561                                if (defaultlanguage == 'F') {
3562                                        sprintf(tmpstr, "Statut du compte [%s] changé avec succès en [", RFIFOP(fd,6));
3563                                } else {
3564                                        sprintf(tmpstr, "Account [%s] state successfully changed in [", RFIFOP(fd,6));
3565                                }
3566                                switch(RFIFOL(fd,30)) {
3567                                case 0:
3568                                        if (defaultlanguage == 'F')
3569                                                strcat(tmpstr, "0: Compte Ok");
3570                                        else
3571                                                strcat(tmpstr, "0: Account OK");
3572                                        break;
3573                                case 1:
3574                                        strcat(tmpstr, "1: Unregistered ID");
3575                                        break;
3576                                case 2:
3577                                        strcat(tmpstr, "2: Incorrect Password");
3578                                        break;
3579                                case 3:
3580                                        strcat(tmpstr, "3: This ID is expired");
3581                                        break;
3582                                case 4:
3583                                        strcat(tmpstr, "4: Rejected from Server");
3584                                        break;
3585                                case 5:
3586                                        strcat(tmpstr, "5: You have been blocked by the GM Team");
3587                                        break;
3588                                case 6:
3589                                        strcat(tmpstr, "6: [Your Game's EXE file is not the latest version");
3590                                        break;
3591                                case 7:
3592                                        strcat(tmpstr, "7: You are Prohibited to log in until...");
3593                                        break;
3594                                case 8:
3595                                        strcat(tmpstr, "8: Server is jammed due to over populated");
3596                                        break;
3597                                case 9:
3598                                        strcat(tmpstr, "9: No MSG");
3599                                        break;
3600                                default: // 100
3601                                        strcat(tmpstr, "100: This ID is totally erased");
3602                                        break;
3603                                }
3604                                strcat(tmpstr, "]");
3605                                ShowMessage("%s\n", tmpstr);
3606                                ladmin_log("%s\n", tmpstr);
3607                        }
3608                        bytes_to_read = 0;
3609                        RFIFOSKIP(fd,34);
3610                        break;
3611
3612                case 0x7939:    // answer of the number of online players
3613                        if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
3614                                return 0;
3615                  {
3616                        // Get length of the received packet
3617                        int i;
3618                        char name[20];
3619                        if (defaultlanguage == 'F') {
3620                                ladmin_log("  Réception du nombre de joueurs en ligne.\n");
3621                        } else {
3622                                ladmin_log("  Receiving of the number of online players.\n");
3623                        }
3624                        // Read information of the servers
3625                        if (RFIFOW(fd,2) < 5) {
3626                                if (defaultlanguage == 'F') {
3627                                        ShowMessage("  Aucun serveur n'est connecté au login serveur.\n");
3628                                } else {
3629                                        ShowMessage("  No server is connected to the login-server.\n");
3630                                }
3631                        } else {
3632                                if (defaultlanguage == 'F') {
3633                                        ShowMessage("  Nombre de joueurs en ligne (serveur: nb):\n");
3634                                } else {
3635                                        ShowMessage("  Number of online players (server: number).\n");
3636                                }
3637                                // Displaying of result
3638                                for(i = 4; i < RFIFOW(fd,2); i += 32) {
3639                                        memcpy(name, RFIFOP(fd,i+6), sizeof(name));
3640                                        name[sizeof(name) - 1] = '\0';
3641                                        ShowMessage("    %-20s : %5d\n", name, RFIFOW(fd,i+26));
3642                                }
3643                        }
3644                  }
3645                        bytes_to_read = 0;
3646                        RFIFOSKIP(fd,RFIFOW(fd,2));
3647                        break;
3648
3649                case 0x793b:    // answer of the check of a password
3650                        if (RFIFOREST(fd) < 30)
3651                                return 0;
3652                        id = RFIFOL(fd,2);
3653                        if (id == -1) {
3654                                if (defaultlanguage == 'F') {
3655                                        ShowMessage("Le compte [%s] n'existe pas ou le mot de passe est incorrect.\n", RFIFOP(fd,6));
3656                                        ladmin_log("Le compte [%s] n'existe pas ou le mot de passe est incorrect.\n", RFIFOP(fd,6));
3657                                } else {
3658                                        ShowMessage("The account [%s] doesn't exist or the password is incorrect.\n", RFIFOP(fd,6));
3659                                        ladmin_log("The account [%s] doesn't exist or the password is incorrect.\n", RFIFOP(fd,6));
3660                                }
3661                        } else {
3662                                if (defaultlanguage == 'F') {
3663                                        ShowMessage("Le mot de passe donné correspond bien au compte [%s][id: %d].\n", RFIFOP(fd,6), id);
3664                                        ladmin_log("Le mot de passe donné correspond bien au compte [%s][id: %d].\n", RFIFOP(fd,6), id);
3665                                } else {
3666                                        ShowMessage("The proposed password is correct for the account [%s][id: %d].\n", RFIFOP(fd,6), id);
3667                                        ladmin_log("The proposed password is correct for the account [%s][id: %d].\n", RFIFOP(fd,6), id);
3668                                }
3669                        }
3670                        bytes_to_read = 0;
3671                        RFIFOSKIP(fd,30);
3672                        break;
3673
3674                case 0x793d:    // answer of the change of an account sex
3675                        if (RFIFOREST(fd) < 30)
3676                                return 0;
3677                        id = RFIFOL(fd,2);
3678                        if (id == -1) {
3679                                if (defaultlanguage == 'F') {
3680                                        ShowMessage("Echec de la modification du sexe du compte [%s].\n", RFIFOP(fd,6));
3681                                        ShowMessage("Le compte [%s] n'existe pas ou le sexe est déjà celui demandé.\n", RFIFOP(fd,6));
3682                                        ladmin_log("Echec de la modification du sexe du compte. Le compte [%s] n'existe pas ou le sexe est déjà celui demandé.\n", RFIFOP(fd,6));
3683                                } else {
3684                                        ShowMessage("Account [%s] sex changing failed.\n", RFIFOP(fd,6));
3685                                        ShowMessage("Account [%s] doesn't exist or the sex is already the good sex.\n", RFIFOP(fd,6));
3686                                        ladmin_log("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n", RFIFOP(fd,6));
3687                                }
3688                        } else {
3689                                if (defaultlanguage == 'F') {
3690                                        ShowMessage("Sexe du compte [%s][id: %d] changé avec succès.\n", RFIFOP(fd,6), id);
3691                                        ladmin_log("Sexe du compte [%s][id: %d] changé avec succès.\n", RFIFOP(fd,6), id);
3692                                } else {
3693                                        ShowMessage("Account [%s][id: %d] sex successfully changed.\n", RFIFOP(fd,6), id);
3694                                        ladmin_log("Account [%s][id: %d] sex successfully changed.\n", RFIFOP(fd,6), id);
3695                                }
3696                        }
3697                        bytes_to_read = 0;
3698                        RFIFOSKIP(fd,30);
3699                        break;
3700
3701                case 0x793f:    // answer of the change of an account GM level
3702                        if (RFIFOREST(fd) < 30)
3703                                return 0;
3704                        id = RFIFOL(fd,2);
3705                        if (id == -1) {
3706                                if (defaultlanguage == 'F') {
3707                                        ShowMessage("Echec de la modification du niveau de GM du compte [%s].\n", RFIFOP(fd,6));
3708                                        ShowMessage("Le compte [%s] n'existe pas, le niveau de GM est déjà celui demandé\n", RFIFOP(fd,6));
3709                                        ShowMessage("ou il est impossible de modifier le fichier des comptes GM.\n");
3710                                        ladmin_log("Echec de la modification du niveau de GM du compte. Le compte [%s] n'existe pas, le niveau de GM est déjà celui demandé ou il est impossible de modifier le fichier des comptes GM.\n", RFIFOP(fd,6));
3711                                } else {
3712                                        ShowMessage("Account [%s] GM level changing failed.\n", RFIFOP(fd,6));
3713                                        ShowMessage("Account [%s] doesn't exist, the GM level is already the good GM level\n", RFIFOP(fd,6));
3714                                        ShowMessage("or it's impossible to modify the GM accounts file.\n");
3715                                        ladmin_log("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n", RFIFOP(fd,6));
3716                                }
3717                        } else {
3718                                if (defaultlanguage == 'F') {
3719                                        ShowMessage("Niveau de GM du compte [%s][id: %d] changé avec succès.\n", RFIFOP(fd,6), id);
3720                                        ladmin_log("Niveau de GM du compte [%s][id: %d] changé avec succès.\n", RFIFOP(fd,6), id);
3721                                } else {
3722                                        ShowMessage("Account [%s][id: %d] GM level successfully changed.\n", RFIFOP(fd,6), id);
3723                                        ladmin_log("Account [%s][id: %d] GM level successfully changed.\n", RFIFOP(fd,6), id);
3724                                }
3725                        }
3726                        bytes_to_read = 0;
3727                        RFIFOSKIP(fd,30);
3728                        break;
3729
3730                case 0x7941:    // answer of the change of an account email
3731                        if (RFIFOREST(fd) < 30)
3732                                return 0;
3733                        id = RFIFOL(fd,2);
3734                        if (id == -1) {
3735                                if (defaultlanguage == 'F') {
3736                                        ShowMessage("Echec de la modification de l'e-mail du compte [%s].\n", RFIFOP(fd,6));
3737                                        ShowMessage("Le compte [%s] n'existe pas.\n", RFIFOP(fd,6));
3738                                        ladmin_log("Echec de la modification de l'e-mail du compte. Le compte [%s] n'existe pas.\n", RFIFOP(fd,6));
3739                                } else {
3740                                        ShowMessage("Account [%s] e-mail changing failed.\n", RFIFOP(fd,6));
3741                                        ShowMessage("Account [%s] doesn't exist.\n", RFIFOP(fd,6));
3742                                        ladmin_log("Account e-mail changing failed. The compte [%s] doesn't exist.\n", RFIFOP(fd,6));
3743                                }
3744                        } else {
3745                                if (defaultlanguage == 'F') {
3746                                        ShowMessage("Modification de l'e-mail du compte [%s][id: %d] réussie.\n", RFIFOP(fd,6), id);
3747                                        ladmin_log("Modification de l'e-mail du compte [%s][id: %d] réussie.\n", RFIFOP(fd,6), id);
3748                                } else {
3749                                        ShowMessage("Account [%s][id: %d] e-mail successfully changed.\n", RFIFOP(fd,6), id);
3750                                        ladmin_log("Account [%s][id: %d] e-mail successfully changed.\n", RFIFOP(fd,6), id);
3751                                }
3752                        }
3753                        bytes_to_read = 0;
3754                        RFIFOSKIP(fd,30);
3755                        break;
3756
3757                case 0x7943:    // answer of the change of an account memo
3758                        if (RFIFOREST(fd) < 30)
3759                                return 0;
3760                        id = RFIFOL(fd,2);
3761                        if (id == -1) {
3762                                if (defaultlanguage == 'F') {
3763                                        ShowMessage("Echec du changement du mémo du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3764                                        ladmin_log("Echec du changement du mémo du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3765                                } else {
3766                                        ShowMessage("Account [%s] memo changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3767                                        ladmin_log("Account [%s] memo changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3768                                }
3769                        } else {
3770                                if (defaultlanguage == 'F') {
3771                                        ShowMessage("Mémo du compte [%s][id: %d] changé avec succès.\n", RFIFOP(fd,6), id);
3772                                        ladmin_log("Mémo du compte [%s][id: %d] changé avec succès.\n", RFIFOP(fd,6), id);
3773                                } else {
3774                                        ShowMessage("Account [%s][id: %d] memo successfully changed.\n", RFIFOP(fd,6), id);
3775                                        ladmin_log("Account [%s][id: %d] memo successfully changed.\n", RFIFOP(fd,6), id);
3776                                }
3777                        }
3778                        bytes_to_read = 0;
3779                        RFIFOSKIP(fd,30);
3780                        break;
3781
3782                case 0x7945:    // answer of an account id search
3783                        if (RFIFOREST(fd) < 30)
3784                                return 0;
3785                        id = RFIFOL(fd,2);
3786                        if (id == -1) {
3787                                if (defaultlanguage == 'F') {
3788                                        ShowMessage("Impossible de trouver l'id du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3789                                        ladmin_log("Impossible de trouver l'id du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3790                                } else {
3791                                        ShowMessage("Unable to find the account [%s] id. Account doesn't exist.\n", RFIFOP(fd,6));
3792                                        ladmin_log("Unable to find the account [%s] id. Account doesn't exist.\n", RFIFOP(fd,6));
3793                                }
3794                        } else {
3795                                if (defaultlanguage == 'F') {
3796                                        ShowMessage("Le compte [%s] a pour id: %d.\n", RFIFOP(fd,6), id);
3797                                        ladmin_log("Le compte [%s] a pour id: %d.\n", RFIFOP(fd,6), id);
3798                                } else {
3799                                        ShowMessage("The account [%s] have the id: %d.\n", RFIFOP(fd,6), id);
3800                                        ladmin_log("The account [%s] have the id: %d.\n", RFIFOP(fd,6), id);
3801                                }
3802                        }
3803                        bytes_to_read = 0;
3804                        RFIFOSKIP(fd,30);
3805                        break;
3806
3807                case 0x7947:    // answer of an account name search
3808                        if (RFIFOREST(fd) < 30)
3809                                return 0;
3810                        id = RFIFOL(fd,2);
3811                        if (strcmp((const char*)RFIFOP(fd,6), "") == 0) {
3812                                if (defaultlanguage == 'F') {
3813                                        ShowMessage("Impossible de trouver le nom du compte [%d]. Le compte n'existe pas.\n", id);
3814                                        ladmin_log("Impossible de trouver le nom du compte [%d]. Le compte n'existe pas.\n", id);
3815                                } else {
3816                                        ShowMessage("Unable to find the account [%d] name. Account doesn't exist.\n", id);
3817                                        ladmin_log("Unable to find the account [%d] name. Account doesn't exist.\n", id);
3818                                }
3819                        } else {
3820                                if (defaultlanguage == 'F') {
3821                                        ShowMessage("Le compte [id: %d] a pour nom: %s.\n", id, RFIFOP(fd,6));
3822                                        ladmin_log("Le compte [id: %d] a pour nom: %s.\n", id, RFIFOP(fd,6));
3823                                } else {
3824                                        ShowMessage("The account [id: %d] have the name: %s.\n", id, RFIFOP(fd,6));
3825                                        ladmin_log("The account [id: %d] have the name: %s.\n", id, RFIFOP(fd,6));
3826                                }
3827                        }
3828                        bytes_to_read = 0;
3829                        RFIFOSKIP(fd,30);
3830                        break;
3831
3832                case 0x7949:    // answer of an account validity limit set
3833                        if (RFIFOREST(fd) < 34)
3834                                return 0;
3835                        id = RFIFOL(fd,2);
3836                        if (id == -1) {
3837                                if (defaultlanguage == 'F') {
3838                                        ShowMessage("Echec du changement de la validité du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3839                                        ladmin_log("Echec du changement de la validité du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3840                                } else {
3841                                        ShowMessage("Account [%s] validity limit changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3842                                        ladmin_log("Account [%s] validity limit changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3843                                }
3844                        } else {
3845                                time_t timestamp = RFIFOL(fd,30);
3846                                if (timestamp == 0) {
3847                                        if (defaultlanguage == 'F') {
3848                                                ShowMessage("Limite de validité du compte [%s][id: %d] changée avec succès en [illimité].\n", RFIFOP(fd,6), id);
3849                                                ladmin_log("Limite de validité du compte [%s][id: %d] changée avec succès en [illimité].\n", RFIFOP(fd,6), id);
3850                                        } else {
3851                                                ShowMessage("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n", RFIFOP(fd,6), id);
3852                                                ladmin_log("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n", RFIFOP(fd,6), id);
3853                                        }
3854                                } else {
3855                                        char tmpstr[128];
3856                                        strftime(tmpstr, 24, date_format, localtime(&timestamp));
3857                                        if (defaultlanguage == 'F') {
3858                                                ShowMessage("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
3859                                                ladmin_log("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
3860                                        } else {
3861                                                ShowMessage("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
3862                                                ladmin_log("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
3863                                        }
3864                                }
3865                        }
3866                        bytes_to_read = 0;
3867                        RFIFOSKIP(fd,34);
3868                        break;
3869
3870                case 0x794b:    // answer of an account ban set
3871                        if (RFIFOREST(fd) < 34)
3872                                return 0;
3873                        id = RFIFOL(fd,2);
3874                        if (id == -1) {
3875                                if (defaultlanguage == 'F') {
3876                                        ShowMessage("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3877                                        ladmin_log("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3878                                } else {
3879                                        ShowMessage("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3880                                        ladmin_log("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3881                                }
3882                        } else {
3883                                time_t timestamp = RFIFOL(fd,30);
3884                                if (timestamp == 0) {
3885                                        if (defaultlanguage == 'F') {
3886                                                ShowMessage("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie].\n", RFIFOP(fd,6), id);
3887                                                ladmin_log("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie].\n", RFIFOP(fd,6), id);
3888                                        } else {
3889                                                ShowMessage("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", RFIFOP(fd,6), id);
3890                                                ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", RFIFOP(fd,6), id);
3891                                        }
3892                                } else {
3893                                        char tmpstr[128];
3894                                        strftime(tmpstr, 24, date_format, localtime(&timestamp));
3895                                        if (defaultlanguage == 'F') {
3896                                                ShowMessage("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
3897                                                ladmin_log("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
3898                                        } else {
3899                                                ShowMessage("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
3900                                                ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
3901                                        }
3902                                }
3903                        }
3904                        bytes_to_read = 0;
3905                        RFIFOSKIP(fd,34);
3906                        break;
3907
3908                case 0x794d:    // answer of an account ban date/time changing
3909                        if (RFIFOREST(fd) < 34)
3910                                return 0;
3911                        id = RFIFOL(fd,2);
3912                        if (id == -1) {
3913                                if (defaultlanguage == 'F') {
3914                                        ShowMessage("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3915                                        ladmin_log("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3916                                } else {
3917                                        ShowMessage("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3918                                        ladmin_log("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3919                                }
3920                        } else {
3921                                time_t timestamp = RFIFOL(fd,30);
3922                                if (timestamp == 0) {
3923                                        if (defaultlanguage == 'F') {
3924                                                ShowMessage("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie].\n", RFIFOP(fd,6), id);
3925                                                ladmin_log("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie].\n", RFIFOP(fd,6), id);
3926                                        } else {
3927                                                ShowMessage("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", RFIFOP(fd,6), id);
3928                                                ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", RFIFOP(fd,6), id);
3929                                        }
3930                                } else {
3931                                        char tmpstr[128];
3932                                        strftime(tmpstr, 24, date_format, localtime(&timestamp));
3933                                        if (defaultlanguage == 'F') {
3934                                                ShowMessage("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
3935                                                ladmin_log("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
3936                                        } else {
3937                                                ShowMessage("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
3938                                                ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
3939                                        }
3940                                }
3941                        }
3942                        bytes_to_read = 0;
3943                        RFIFOSKIP(fd,34);
3944                        break;
3945
3946                case 0x794f:    // answer of a broadcast
3947                        if (RFIFOREST(fd) < 4)
3948                                return 0;
3949                        if (RFIFOW(fd,2) == (unsigned short)-1) {
3950                                if (defaultlanguage == 'F') {
3951                                        ShowMessage("Echec de l'envoi du message. Aucun server de char en ligne.\n");
3952                                        ladmin_log("Echec de l'envoi du message. Aucun server de char en ligne.\n");
3953                                } else {
3954                                        ShowMessage("Message sending failed. No online char-server.\n");
3955                                        ladmin_log("Message sending failed. No online char-server.\n");
3956                                }
3957                        } else {
3958                                if (defaultlanguage == 'F') {
3959                                        ShowMessage("Message transmis au server de logins avec succès.\n");
3960                                        ladmin_log("Message transmis au server de logins avec succès.\n");
3961                                } else {
3962                                        ShowMessage("Message successfully sended to login-server.\n");
3963                                        ladmin_log("Message successfully sended to login-server.\n");
3964                                }
3965                        }
3966                        bytes_to_read = 0;
3967                        RFIFOSKIP(fd,4);
3968                        break;
3969
3970                case 0x7951:    // answer of an account validity limit changing
3971                        if (RFIFOREST(fd) < 34)
3972                                return 0;
3973                        id = RFIFOL(fd,2);
3974                        if (id == -1) {
3975                                if (defaultlanguage == 'F') {
3976                                        ShowMessage("Echec du changement de la validité du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3977                                        ladmin_log("Echec du changement de la validité du compte [%s]. Le compte n'existe pas.\n", RFIFOP(fd,6));
3978                                } else {
3979                                        ShowMessage("Account [%s] validity limit changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3980                                        ladmin_log("Account [%s] validity limit changing failed. Account doesn't exist.\n", RFIFOP(fd,6));
3981                                }
3982                        } else {
3983                                time_t timestamp = RFIFOL(fd,30);
3984                                if (timestamp == 0) {
3985                                        if (defaultlanguage == 'F') {
3986                                                ShowMessage("Limite de validité du compte [%s][id: %d] inchangée.\n", RFIFOP(fd,6), id);
3987                                                ShowMessage("Le compte a une validité illimitée ou\n");
3988                                                ShowMessage("la modification est impossible avec les ajustements demandés.\n");
3989                                                ladmin_log("Limite de validité du compte [%s][id: %d] inchangée. Le compte a une validité illimitée ou la modification est impossible avec les ajustements demandés.\n", RFIFOP(fd,6), id);
3990                                        } else {
3991                                                ShowMessage("Validity limit of the account [%s][id: %d] unchanged.\n", RFIFOP(fd,6), id);
3992                                                ShowMessage("The account have an unlimited validity limit or\n");
3993                                                ShowMessage("the changing is impossible with the proposed adjustments.\n");
3994                                                ladmin_log("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n", RFIFOP(fd,6), id);
3995                                        }
3996                                } else {
3997                                        char tmpstr[128];
3998                                        strftime(tmpstr, 24, date_format, localtime(&timestamp));
3999                                        if (defaultlanguage == 'F') {
4000                                                ShowMessage("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
4001                                                ladmin_log("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP(fd,6), id, tmpstr);
4002                                        } else {
4003                                                ShowMessage("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
4004                                                ladmin_log("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n", RFIFOP(fd,6), id, tmpstr);
4005                                        }
4006                                }
4007                        }
4008                        bytes_to_read = 0;
4009                        RFIFOSKIP(fd,34);
4010                        break;
4011
4012                case 0x7953:    // answer of a request about informations of an account (by account name/id)
4013                        if (RFIFOREST(fd) < 150 || RFIFOREST(fd) < (size_t)(150 + RFIFOW(fd,148)))
4014                                return 0;
4015                  {
4016                        char userid[24], error_message[20], lastlogin[24], last_ip[16], email[40], memo[255];
4017                        time_t unban_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
4018                        time_t expiration_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
4019                        memcpy(userid, RFIFOP(fd,7), sizeof(userid));
4020                        userid[sizeof(userid)-1] = '\0';
4021                        memcpy(error_message, RFIFOP(fd,40), sizeof(error_message));
4022                        error_message[sizeof(error_message)-1] = '\0';
4023                        memcpy(lastlogin, RFIFOP(fd,60), sizeof(lastlogin));
4024                        lastlogin[sizeof(lastlogin)-1] = '\0';
4025                        memcpy(last_ip, RFIFOP(fd,84), sizeof(last_ip));
4026                        last_ip[sizeof(last_ip)-1] = '\0';
4027                        memcpy(email, RFIFOP(fd,100), sizeof(email));
4028                        email[sizeof(email)-1] = '\0';
4029                        expiration_time = (time_t)RFIFOL(fd,140);
4030                        unban_time = (time_t)RFIFOL(fd,144);
4031                        memset(memo, '\0', sizeof(memo));
4032                        strncpy(memo, (const char*)RFIFOP(fd,150), RFIFOW(fd,148));
4033                        id = RFIFOL(fd,2);
4034                        if (id == -1) {
4035                                if (defaultlanguage == 'F') {
4036                                        ShowMessage("Impossible de trouver le compte [%s]. Le compte n'existe pas.\n", parameters);
4037                                        ladmin_log("Impossible de trouver le compte [%s]. Le compte n'existe pas.\n", parameters);
4038                                } else {
4039                                        ShowMessage("Unabled to find the account [%s]. Account doesn't exist.\n", parameters);
4040                                        ladmin_log("Unabled to find the account [%s]. Account doesn't exist.\n", parameters);
4041                                }
4042                        } else if (strlen(userid) == 0) {
4043                                if (defaultlanguage == 'F') {
4044                                        ShowMessage("Impossible de trouver le compte [id: %s]. Le compte n'existe pas.\n", parameters);
4045                                        ladmin_log("Impossible de trouver le compte [id: %s]. Le compte n'existe pas.\n", parameters);
4046                                } else {
4047                                        ShowMessage("Unabled to find the account [id: %s]. Account doesn't exist.\n", parameters);
4048                                        ladmin_log("Unabled to find the account [id: %s]. Account doesn't exist.\n", parameters);
4049                                }
4050                        } else {
4051                                if (defaultlanguage == 'F') {
4052                                        ladmin_log("Réception d'information concernant un compte.\n");
4053                                        ShowMessage("Le compte a les caractéristiques suivantes:\n");
4054                                } else {
4055                                        ladmin_log("Receiving information about an account.\n");
4056                                        ShowMessage("The account is set with:\n");
4057                                }
4058                                if (RFIFOB(fd,6) == 0) {
4059                                        ShowMessage(" Id:     %d (non-GM)\n", id);
4060                                } else {
4061                                        if (defaultlanguage == 'F') {
4062                                                ShowMessage(" Id:     %d (GM niveau %d)\n", id, (int)RFIFOB(fd,6));
4063                                        } else {
4064                                                ShowMessage(" Id:     %d (GM level %d)\n", id, (int)RFIFOB(fd,6));
4065                                        }
4066                                }
4067                                if (defaultlanguage == 'F') {
4068                                        ShowMessage(" Nom:    '%s'\n", userid);
4069                                        if (RFIFOB(fd,31) == 0)
4070                                                ShowMessage(" Sexe:   Femme\n");
4071                                        else if (RFIFOB(fd,31) == 1)
4072                                                ShowMessage(" Sexe:   Male\n");
4073                                        else
4074                                                ShowMessage(" Sexe:   Serveur\n");
4075                                } else {
4076                                        ShowMessage(" Name:   '%s'\n", userid);
4077                                        if (RFIFOB(fd,31) == 0)
4078                                                ShowMessage(" Sex:    Female\n");
4079                                        else if (RFIFOB(fd,31) == 1)
4080                                                ShowMessage(" Sex:    Male\n");
4081                                        else
4082                                                ShowMessage(" Sex:    Server\n");
4083                                }
4084                                ShowMessage(" E-mail: %s\n", email);
4085                                switch(RFIFOL(fd,36)) {
4086                                case 0:
4087                                        if (defaultlanguage == 'F')
4088                                                ShowMessage(" Statut: 0 [Compte Ok]\n");
4089                                        else
4090                                                ShowMessage(" State: 0 [Account OK]\n");
4091                                        break;
4092                                case 1:
4093                                        ShowMessage(" Statut: 1 [Unregistered ID]\n");
4094                                        break;
4095                                case 2:
4096                                        ShowMessage(" State: 2 [Incorrect Password]\n");
4097                                        break;
4098                                case 3:
4099                                        ShowMessage(" Statut: 3 [This ID is expired]\n");
4100                                        break;
4101                                case 4:
4102                                        ShowMessage(" State: 4 [Rejected from Server]\n");
4103                                        break;
4104                                case 5:
4105                                        ShowMessage(" Statut: 5 [You have been blocked by the GM Team]\n");
4106                                        break;
4107                                case 6:
4108                                        ShowMessage(" State: 6 [Your Game's EXE file is not the latest version]\n");
4109                                        break;
4110                                case 7:
4111                                        ShowMessage(" Statut: 7 [You are Prohibited to log in until %s]\n", error_message);
4112                                        break;
4113                                case 8:
4114                                        ShowMessage(" State: 8 [Server is jammed due to over populated]\n");
4115                                        break;
4116                                case 9:
4117                                        ShowMessage(" Statut: 9 [No MSG]\n");
4118                                        break;
4119                                default: // 100
4120                                        ShowMessage(" State: %d [This ID is totally erased]\n", (int)RFIFOL(fd,36));
4121                                        break;
4122                                }
4123                                if (defaultlanguage == 'F') {
4124                                        if (unban_time == 0) {
4125                                                ShowMessage(" Banissement: non banni.\n");
4126                                        } else {
4127                                                char tmpstr[128];
4128                                                strftime(tmpstr, 24, date_format, localtime(&unban_time));
4129                                                ShowMessage(" Banissement: jusqu'au %s.\n", tmpstr);
4130                                        }
4131                                        if (RFIFOL(fd,32) > 1)
4132                                                ShowMessage(" Compteur: %d connexions.\n", (int)RFIFOL(fd,32));
4133                                        else
4134                                                ShowMessage(" Compteur: %d connexion.\n", (int)RFIFOL(fd,32));
4135                                        ShowMessage(" Dernière connexion le: %s (ip: %s)\n", lastlogin, last_ip);
4136                                        if (expiration_time == 0) {
4137                                                ShowMessage(" Limite de validité: illimité.\n");
4138                                        } else {
4139                                                char tmpstr[128];
4140                                                strftime(tmpstr, 24, date_format, localtime(&expiration_time));
4141                                                ShowMessage(" Limite de validité: jusqu'au %s.\n", tmpstr);
4142                                        }
4143                                } else {
4144                                        if (unban_time == 0) {
4145                                                ShowMessage(" Banishment: not banished.\n");
4146                                        } else {
4147                                                char tmpstr[128];
4148                                                strftime(tmpstr, 24, date_format, localtime(&unban_time));
4149                                                ShowMessage(" Banishment: until %s.\n", tmpstr);
4150                                        }
4151                                        if (RFIFOL(fd,32) > 1)
4152                                                ShowMessage(" Count:  %d connections.\n", (int)RFIFOL(fd,32));
4153                                        else
4154                                                ShowMessage(" Count:  %d connection.\n", (int)RFIFOL(fd,32));
4155                                        ShowMessage(" Last connection at: %s (ip: %s)\n", lastlogin, last_ip);
4156                                        if (expiration_time == 0) {
4157                                                ShowMessage(" Validity limit: unlimited.\n");
4158                                        } else {
4159                                                char tmpstr[128];
4160                                                strftime(tmpstr, 24, date_format, localtime(&expiration_time));
4161                                                ShowMessage(" Validity limit: until %s.\n", tmpstr);
4162                                        }
4163                                }
4164                                ShowMessage(" Memo:   '%s'\n", memo);
4165                        }
4166                  }
4167                        bytes_to_read = 0;
4168                        RFIFOSKIP(fd,150 + RFIFOW(fd,148));
4169                        break;
4170
4171                default:
4172                        ShowMessage("Remote administration has been disconnected (unknown packet).\n");
4173                        ladmin_log("'End of connection, unknown packet.\n");
4174                        set_eof(fd);
4175                        return 0;
4176                }
4177        }
4178
4179        // if we don't wait new packets, do the prompt
4180        prompt();
4181
4182        return 0;
4183}
4184
4185//------------------------------------
4186// Function to connect to login-server
4187//------------------------------------
4188int Connect_login_server(void)
4189{
4190        if (defaultlanguage == 'F') {
4191                ShowMessage("Essai de connection au server de logins...\n");
4192                ladmin_log("Essai de connection au server de logins...\n");
4193        } else {
4194                ShowMessage("Attempt to connect to login-server...\n");
4195                ladmin_log("Attempt to connect to login-server...\n");
4196        }
4197
4198        login_fd = make_connection(login_ip, loginserverport);
4199        if (login_fd == -1)
4200        {       //Might not be the most elegant way to handle this, but I've never used ladmin so I dunno what else you could do. [Skotlex]
4201                ShowMessage("Error: Failed to connect to Login Server\n");
4202                exit(EXIT_FAILURE);
4203        }
4204        session[login_fd]->flag.server = 1;
4205        if (passenc == 0) {
4206                WFIFOHEAD(login_fd,28);
4207                WFIFOW(login_fd,0) = 0x7918; // Request for administation login
4208                WFIFOW(login_fd,2) = 0; // no encrypted
4209                memcpy(WFIFOP(login_fd,4), loginserveradminpassword, 24);
4210                WFIFOSET(login_fd,28);
4211                bytes_to_read = 1;
4212                if (defaultlanguage == 'F') {
4213                        ShowMessage("Envoi du mot de passe...\n");
4214                        ladmin_log("Envoi du mot de passe...\n");
4215                } else {
4216                        ShowMessage("Sending of the password...\n");
4217                        ladmin_log("Sending of the password...\n");
4218                }
4219        } else {
4220                WFIFOHEAD(login_fd,2);
4221                WFIFOW(login_fd,0) = 0x791a; // Sending request about the coding key
4222                WFIFOSET(login_fd,2);
4223                bytes_to_read = 1;
4224                if (defaultlanguage == 'F') {
4225                        ShowMessage("Demande de la clef MD5...\n");
4226                        ladmin_log("Demande de la clef MD5...\n");
4227                } else {
4228                        ShowMessage("Request about the MD5 key...\n");
4229                        ladmin_log("Request about the MD5 key...\n");
4230                }
4231        }
4232
4233        return 0;
4234}
4235
4236// sends a ping packet to login server (will receive pong 0x2718)
4237int ping_login_server(int tid, unsigned int tick, int id, intptr data)
4238{
4239        if (login_fd > 0 && session[login_fd] != NULL)
4240        {
4241                WFIFOHEAD(login_fd,2);
4242                WFIFOW(login_fd,0) = 0x2719;
4243                WFIFOSET(login_fd,2);
4244        }
4245        return 0;
4246}
4247
4248//-----------------------------------
4249// Reading general configuration file
4250//-----------------------------------
4251int ladmin_config_read(const char *cfgName)
4252{
4253        char line[1024], w1[1024], w2[1024];
4254        FILE *fp;
4255
4256        fp = fopen(cfgName, "r");
4257        if (fp == NULL) {
4258                if (defaultlanguage == 'F') {
4259                        ShowMessage("\033[0mFichier de configuration (%s) non trouvé.\n", cfgName);
4260                } else {
4261                        ShowMessage("\033[0mConfiguration file (%s) not found.\n", cfgName);
4262                }
4263                return 1;
4264        }
4265
4266        if (defaultlanguage == 'F') {
4267                ShowMessage("\033[0m---Début de lecture du fichier de configuration Ladmin (%s)\n", cfgName);
4268        } else {
4269                ShowMessage("\033[0m---Start reading of Ladmin configuration file (%s)\n", cfgName);
4270        }
4271        while(fgets(line, sizeof(line), fp))
4272        {
4273                if (line[0] == '/' && line[1] == '/')
4274                        continue;
4275
4276                if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2) {
4277                        remove_control_chars(w1);
4278                        remove_control_chars(w2);
4279
4280                        if(strcmpi(w1,"login_ip")==0) {
4281                                uint32 ipl = host2ip(w2);
4282                                if (ipl != 0) {
4283                                        ip2str(ipl, loginserverip);
4284                                        if (defaultlanguage == 'F') {
4285                                                ShowMessage("Adresse du serveur de logins: %s -> %s\n", w2, loginserverip);
4286                                        } else {
4287                                                ShowMessage("Login server IP address: %s -> %s\n", w2, loginserverip);
4288                                        }
4289                                } else
4290                                        memcpy(loginserverip, w2, 16);
4291                        } else if (strcmpi(w1, "login_port") == 0) {
4292                                loginserverport = atoi(w2);
4293                        } else if (strcmpi(w1, "admin_pass") == 0) {
4294                                strncpy(loginserveradminpassword, w2, sizeof(loginserveradminpassword));
4295                                loginserveradminpassword[sizeof(loginserveradminpassword)-1] = '\0';
4296                        } else if (strcmpi(w1, "passenc") == 0) {
4297                                passenc = atoi(w2);
4298                                if (passenc < 0 || passenc > 2)
4299                                        passenc = 0;
4300                        } else if (strcmpi(w1, "defaultlanguage") == 0) {
4301                                if (w2[0] == 'F' || w2[0] == 'E')
4302                                        defaultlanguage = w2[0];
4303                        } else if (strcmpi(w1, "ladmin_log_filename") == 0) {
4304                                strncpy(ladmin_log_filename, w2, sizeof(ladmin_log_filename));
4305                                ladmin_log_filename[sizeof(ladmin_log_filename)-1] = '\0';
4306                        } else if (strcmpi(w1, "date_format") == 0) {
4307                                strncpy(date_format, w2, sizeof(date_format));
4308                        } else if(strcmpi(w1,"stdout_with_ansisequence") == 0) {
4309                                stdout_with_ansisequence = config_switch(w2);
4310                        } else if (strcmpi(w1, "import") == 0) {
4311                                ladmin_config_read(w2);
4312                        }
4313                }
4314        }
4315        fclose(fp);
4316
4317        login_ip = str2ip(loginserverip);
4318
4319        if (defaultlanguage == 'F') {
4320                ShowMessage("---Lecture du fichier de configuration Ladmin terminée.\n");
4321        } else {
4322                ShowMessage("---End reading of Ladmin configuration file.\n");
4323        }
4324
4325        return 0;
4326}
4327
4328//------------------------------
4329// Function called when the server
4330// has received a crash signal.
4331//------------------------------
4332void do_abort(void)
4333{
4334}
4335
4336//--------------------------------------
4337// Function called at exit of the server
4338//--------------------------------------
4339void do_final(void)
4340{
4341        if (already_exit_function == 0) {
4342
4343                if (defaultlanguage == 'F') {
4344                        ShowMessage("\033[0m----Fin de Ladmin (fin normale avec fermeture de tous les fichiers).\n");
4345                        ladmin_log("----Fin de Ladmin (fin normale avec fermeture de tous les fichiers).\n");
4346                } else {
4347                        ShowMessage("\033[0m----End of Ladmin (normal end with closing of all files).\n");
4348                        ladmin_log("----End of Ladmin (normal end with closing of all files).\n");
4349                }
4350
4351                already_exit_function = 1;
4352                do_close(login_fd);
4353        }
4354}
4355
4356//------------------------
4357// Main function of ladmin
4358//------------------------
4359int do_init(int argc, char **argv)
4360{
4361        int next;
4362        socket_init();
4363
4364        // read ladmin configuration
4365        ladmin_config_read((argc > 1) ? argv[1] : LADMIN_CONF_NAME);
4366
4367        ladmin_log("");
4368        if (defaultlanguage == 'F') {
4369                ladmin_log("Fichier de configuration lu.\n");
4370        } else {
4371                ladmin_log("Configuration file readed.\n");
4372        }
4373
4374        srand(time(NULL));
4375
4376        set_defaultparse(parse_fromlogin);
4377
4378        if (defaultlanguage == 'F') {
4379                ShowMessage("Outil d'administration à distance de eAthena.\n");
4380                ShowMessage("(pour eAthena version %d.%d.%d.)\n", ATHENA_MAJOR_VERSION, ATHENA_MINOR_VERSION, ATHENA_REVISION);
4381        } else {
4382                ShowMessage("EAthena login-server administration tool.\n");
4383                ShowMessage("(for eAthena version %d.%d.%d.)\n", ATHENA_MAJOR_VERSION, ATHENA_MINOR_VERSION, ATHENA_REVISION);
4384        }
4385
4386        if (defaultlanguage == 'F') {
4387                ladmin_log("Ladmin est prêt.\n");
4388                ShowMessage("Ladmin est \033[1;32mprêt\033[0m.\n\n");
4389        } else {
4390                ladmin_log("Ladmin is ready.\n");
4391                ShowMessage("Ladmin is \033[1;32mready\033[0m.\n\n");
4392        }
4393
4394        Connect_login_server();
4395
4396        // keep the char-login connection alive
4397        add_timer_func_list(ping_login_server, "ping_login_server");
4398        add_timer_interval(gettick() + 1000, ping_login_server, 0, 0, ((int)stall_time-2) * 1000);
4399
4400        // minimalist core doesn't have sockets parsing,
4401        // so we have to do this ourselves
4402        while (runflag) {
4403                next = do_timer(gettick_nocache());
4404                do_sockets(next);
4405        }
4406
4407        return 0;
4408}
Note: See TracBrowser for help on using the browser.