ladmin.c 173 KB

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