ladmin.c 174 KB

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