Browse Source

update

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@968 54d463be-8e91-2dee-dedb-b68131a5f0ec
(no author) 20 năm trước cách đây
mục cha
commit
778e804dd6
75 tập tin đã thay đổi với 2572 bổ sung1837 xóa
  1. 138 0
      Changelog.txt
  2. 3 5
      Dev/bugs.txt
  3. 4 0
      conf-tmpl/battle_athena.conf
  4. 166 152
      db/packet_db.txt
  5. 1 1
      db/skill_cast_db.txt
  6. 124 46
      npc/mobs/fields/yuno.txt
  7. 0 3
      sql-files/database.sql
  8. 0 2
      sql-files/mail.sql
  9. 61 59
      src/char/char.c
  10. 3 3
      src/char/char.h
  11. 12 12
      src/char/int_guild.c
  12. 4 4
      src/char/int_party.c
  13. 4 4
      src/char/int_pet.c
  14. 8 8
      src/char/int_storage.c
  15. 6 6
      src/char/inter.c
  16. 48 48
      src/char_sql/char.c
  17. 3 3
      src/char_sql/char.h
  18. 98 98
      src/char_sql/int_guild.c
  19. 1 1
      src/char_sql/int_party.c
  20. 1 1
      src/char_sql/int_pet.c
  21. 2 2
      src/char_sql/int_storage.c
  22. 2 2
      src/char_sql/inter.c
  23. 4 4
      src/char_sql/itemdb.c
  24. 1 1
      src/char_sql/itemdb.h
  25. 1 0
      src/common/core.c
  26. 3 3
      src/common/db.c
  27. 33 35
      src/common/grfio.c
  28. 2 2
      src/common/grfio.h
  29. 21 2
      src/common/malloc.c
  30. 20 0
      src/common/malloc.h
  31. 19 13
      src/common/mmo.h
  32. 3 2
      src/common/showmsg.c
  33. 34 30
      src/common/socket.c
  34. 2 1
      src/common/socket.h
  35. 11 11
      src/common/strlib.c
  36. 3 3
      src/common/strlib.h
  37. 5 5
      src/common/timer.c
  38. 5 4
      src/common/utils.c
  39. 6 0
      src/common/utils.h
  40. 5 5
      src/ladmin/ladmin.c
  41. 50 40
      src/login/login.c
  42. 1 1
      src/login/login.h
  43. 13 13
      src/login_sql/login.c
  44. 1 1
      src/login_sql/login.h
  45. 86 78
      src/map/atcommand.c
  46. 5 5
      src/map/atcommand.h
  47. 110 59
      src/map/battle.c
  48. 4 3
      src/map/battle.h
  49. 2 2
      src/map/charcommand.c
  50. 3 3
      src/map/chat.c
  51. 203 157
      src/map/clif.c
  52. 10 4
      src/map/clif.h
  53. 18 18
      src/map/guild.c
  54. 1 1
      src/map/guild.h
  55. 5 5
      src/map/intif.c
  56. 1 1
      src/map/intif.h
  57. 7 7
      src/map/itemdb.c
  58. 28 28
      src/map/mail.c
  59. 101 94
      src/map/map.c
  60. 6 5
      src/map/map.h
  61. 221 217
      src/map/mob.c
  62. 3 3
      src/map/mob.h
  63. 113 113
      src/map/npc.c
  64. 1 1
      src/map/party.c
  65. 164 82
      src/map/pc.c
  66. 2 2
      src/map/pet.c
  67. 122 118
      src/map/script.c
  68. 342 114
      src/map/skill.c
  69. 8 7
      src/map/skill.h
  70. 6 6
      src/map/storage.c
  71. 3 3
      src/map/vending.c
  72. 53 53
      src/txt-converter/char/char-converter.c
  73. 3 3
      src/txt-converter/char/char.h
  74. 5 5
      src/txt-converter/common/mmo.h
  75. 4 4
      src/txt-converter/login/login-converter.c

+ 138 - 0
Changelog.txt

@@ -1,4 +1,142 @@
 Date	Added
+
+01/23
+	* Forgot a couple small changes [SVN 35] [Ajarn]
+	* Changed map_data.gat and map_data_other_server.gat from unsigned char*
+	  to char* (this might be needed, because of unicode or something, please
+	  correct me if I'm wrong) [SVN 34] [Ajarn]
+	* Converted decode_zip, enconde_zip, remove_control_chars, mapif_sendall*,
+	  and e_mail_check to use char* instead of unsigned char* (again, please test)
+	  [SVN 34] [Ajarn]
+        * Modified skill unit group checking in skill_unit_onplace that might have
+          been causing crashes [celest]
+        * Updated packet 0x143 length's for version 14 (2004-11-01Sakexe) and version
+          16 (2005-01-10Sakexe), thanks to jathena and ice2big [celest]
+        * Fixed login-server compile error with the "new" -> "new_" changes [celest]
+
+01/22
+	* Fixed an error that was in my last commit (optimising g++ build) [SVN 29]
+	  [Ajarn]
+	* Made strlib functions char*, instead of unsigned char*. Strings are meant
+	  to be char. (Shouldn't break anyhting, but might, please test this for me)
+	  [SVN 26] [Ajarn]
+	* Added cast for TXT version [SVN 25] [Ajarn]
+	* Added cast from allocation calls, from void* to intended type [SVN 24] [Ajarn]
+	* Changed bool -> bool_. Still need to make convertions between
+	  char* and unsigned char* valid, and some other convertions too.
+	  Also, sizeof is being used wierd in map.c, at least g++
+	  complains [SVN 22] [Ajarn]
+	* Changed the rest of the class variable names to class_ and all the new
+	  variable names to new_, for futher g++ support [SVN 21] [Ajarn]
+        * Update both caster and target's SP after using Soul Change -- thanks to Aalye
+          / Freya [celest]
+        * Force a monster to switch attack target when being casted Provoke [celest]
+        * Corrected description for @enablenpc -- "@npcon" -> "@enablenpc" [celest]
+        * Since job normalising is still buggy require all 1st class skills to check
+          for Basic Skill level when calculating the skill tree [celest]
+
+01/21
+        * Updated packet DB configurations : enable_packet_db, packet_db_ver,
+          -- check the .txt for description [celest]
+
+          Note: For people having connection problems try setting 'enable_packet_db'
+          to 'no'... and use the latest client (01-10Sakexe)
+
+        * Fixed a small typo in 12-06's packets -- 21b => 21d [celest]
+        * Updated packet_db.txt to only contain the latest version, like jAthena,
+          since there's not much point to re-read packets eA already supports 
+          (although if you remove all the //'s it can still read multiple versions)
+          [celest]
+        * Added clif_config in clif.c - for keeping packet/client connections related
+          stuff [celest]
+        * Send 'Game Exe not latest version' to a client if it hasn't been authentified
+          yet, but is sending a non-connection-related packet to prevent crashing
+          -- assume the client is using an unknown exe [celest]
+
+01/20
+	* Fixed compile time problems with the non-GC case [MouseJstr]
+	* Introduced aMallocA and aCallocA
+
+	  These two functions allocate "atomic" memory which means 
+	  "memory that does not contain references to other memory".
+
+	  This lets the garbage collector ignore these objects when searching
+	  memory for references to other objects dramatically increasing
+	  performance of the GC.  
+
+	  When in doubt, use aMalloc and aCalloc.  It is better to add
+	  a tiny bit of work to the GC then do cause a crash due to memory
+	  being cleaned up when it shouldn't.
+	  [MouseJstr]
+	* Modified all calls to aMalloc and aCalloc that reference
+	  atomic memory to use aMallocA and aCallocA
+	  [MouseJstr]
+	* Modified the socket buffer allocator to use "atomic" memory
+	  for the fifo data buffers [MouseJstr]
+01/19
+	* added support for the Hans-J. Boehm libC garbage collector
+	  (A copy is in http://amber.stormbirds.org/~joshs/gc6.3.tar).  
+
+	  It is ABSOLUTELY critical for people to use
+	  aFree/aMalloc/aCalloc/aStrdup for this to work.  If somebody
+	  has just used free or malloc, this will crash when used with
+	  the garbage collector.  
+
+	  A amusing environmental variable to set is GC_PRINT_STATS (to 1)
+	  so that you see real time statistics of leaked data being
+	  recovered.  
+
+	  grab a copy of the gc6.3.tar.. build it .. install it.. 
+	  modify the Makefile to have the 
+
+		CC = gcc -pipe -DGCOLLECT
+		GCLIB = -lgc
+
+	  lines... and make the sql servers (the txt server doesn't
+	  build using this right now due to stupid Makefile issues)
+
+	  [MouseJstr]
+	* SVN 3 on http://svn.stormbirds.org/svn/eathena will be what
+	  I diff against when I merge back into delta.. if we ever merge
+	  back into delta   [MouseJstr]
+        * Removed 12-06 Sakexe detection, since it doesn't seem to work, and
+          might be conflicting with 10-25 clients [celest]
+        * Update the Soul Burn target's SP when it has been successfully reduced to 0,
+          thanks to Aalye / Freya [celest]
+        * Moved SC_PRESERVE and SC_BATTLEORDERS's id so they'll display a status icon
+          when cast, thanks XiaoLin of cAthena [celest]
+        * Added missing code for Preserve -- i totally forgot to add it ^^; [celest]
+
+01/18
+        * Added some skill bug fixes, thanks to Aalye / Freya [celest]
+          - stop player attacking if the target goes into hiding
+          - fixed Sword Reject not working against swords, only daggers
+          - additional check in case Marionette Control doesn't end properly even
+            when one of the partners has logged off
+        * Added stun, bleeding and SP loss effect for Pressure, thanks to DracoRpg
+          [celest]
+        * TEST: Fixed more compile warnings in MSVC [celest]
+        * TEST: Fixed some compile errors in MS Visual C++, thanks to Ser [celest]
+
+01/17
+        * Some rewrites in skill_delayfix [celest]
+          - If the delay is < 0, add the weapon aspd delay to it
+          - If the skill is not weapon type, and has 0 delay, add 300ms as default
+        * Added min_skill_delay_limit as the minimum allowed delay for any skills
+          [celest]
+        * Some tidying up in battle_get_ functions [celest]
+        * Set exp table and job bonus table to 0 before reading - might solve some
+          memory bugs [celest]
+        * Updated skill range leniency code - If possible try and move towards the
+          skill target so that when casting it no longer falls out of range [celest]
+
+01/15
+        * Added effects to enemies for Gospel [celest]
+        * Added mobs spawn to all Yuno fields (according to 4th Jan patch) [Lupus]
+
+01/14
+        * Added party supporting effects for Gospel [celest]
+
 01/13
         * Added and testing support for 2004-12-06Sakexe [celest]
         * Removed emblem changing requiring Glory of Guild limited to TXT only [celest]

+ 3 - 5
Dev/bugs.txt

@@ -221,9 +221,7 @@ Problem:	Berzebub, etc cards don't decrease aftercast delays
 Assigned:	N/A
 Progress:	0%
 
-Problem:	Some clients that are able to log into eAthena servers properly are not able to when custom items are used.
-		I believe Celest may have accidentially "broken" a few things when she was attempting to create new packet
-		compatibility and removed old ones.
+Problem:	Older Clients are unable to log into the server, period. 
+		Even if the packet_db is set to use the older clients, they still are unable to connect.
 Assigned:	Celest
-Progress:	0%
-		Celest: What version was the client using?
+Progress:	0%

+ 4 - 0
conf-tmpl/battle_athena.conf

@@ -46,6 +46,10 @@ delay_rate: 100
 // Note: On Official servers Dex does NOT affect delay time
 delay_dependon_dex: no
 
+// Minimum allowed delay for ANY skills after casting (in miliseconds) (Note 1)
+// Note: Setting this to anything above 0 can stop speedhacks.
+min_skill_delay_limit: 100
+
 // At what dex does the cast time become zero (instacast)
 castrate_dex_scale: 150
 

+ 166 - 152
db/packet_db.txt

@@ -1,11 +1,23 @@
 // The packet database allows you to add support for new clients,
-// because packets change every release. 
-// This only allows 1 type of client at a time, make sure your
+// because packets change every release.
+// By default this only allows 1 type of client at a time, make sure your
 // client is the last one in the list
 // EX: You have client 628 and it goes up to 1021,
 // delete or comment (use //) till your client is last.
 
-packet_ver: 5
+
+// Whether to allow identifying clients via the packet DB
+enable_packet_db: yes
+
+// Main packet version of the DB (default = Auto Detect)
+packet_db_ver: default
+
+// Whether the packet DB takes higher precedence over the hardcoded packet
+// length and functions, and whether to overwrite them when reading
+prefer_packet_db: yes
+
+
+// packet_ver: 5
 0x0064,55
 0x0065,17
 0x0066,3
@@ -438,182 +450,182 @@ packet_ver: 5
 //jRO‚Í‚±‚±‚Ü‚Å
 
 //2004-07-06kRO
-packet_ver: 6
-0x0072,22,wanttoconnection,5:9:13:17:21
-0x0085,8,walktoxy,5
-0x00a7,13,useitem,5:9
-0x0113,15,useskilltoid,4:9:11
-0x0116,15,useskilltopos,4:9:11:13
-0x0190,95,useskilltopos,4:9:11:13:15
+// packet_ver: 6
+// 0x0072,22,wanttoconnection,5:9:13:17:21
+// 0x0085,8,walktoxy,5
+// 0x00a7,13,useitem,5:9
+// 0x0113,15,useskilltoid,4:9:11
+// 0x0116,15,useskilltopos,4:9:11:13
+// 0x0190,95,useskilltopos,4:9:11:13:15
 
 //2004-07-13kRO
-packet_ver: 7
-0x0072,39,wanttoconnection,12:22:30:34:38
-0x0085,9,walktoxy,6
-0x009b,13,changedir,5:12
-0x009f,10,takeitem,6
-0x00a7,17,useitem,6:13
-0x0113,19,useskilltoid,7:9:15
-0x0116,19,useskilltopos,7:9:15:17
-0x0190,99,useskilltopos,7:9:15:17:19
+// packet_ver: 7
+// 0x0072,39,wanttoconnection,12:22:30:34:38
+// 0x0085,9,walktoxy,6
+// 0x009b,13,changedir,5:12
+// 0x009f,10,takeitem,6
+// 0x00a7,17,useitem,6:13
+// 0x0113,19,useskilltoid,7:9:15
+// 0x0116,19,useskilltopos,7:9:15:17
+// 0x0190,99,useskilltopos,7:9:15:17:19
 
 //2004-07-26kRO
-packet_ver: 8
-0x0072,14,dropitem,5:12
-0x007e,33,wanttoconnection,12:18:24:28:32
-0x0085,20,useskilltoid,7:12:16
-0x0089,15,getcharnamerequest,11
-0x008c,23,useskilltopos,3:6:17:21
-0x0094,10,takeitem,6
-0x009b,6,walktoxy,3
-0x009f,13,changedir,5:12
-0x00a2,103,useskilltopos,3:6:17:21:23
-0x00a7,12,solvecharname,8
-0x00f3,-1,globalmessage,2:4
-0x00f5,17,useitem,6:12
-0x00f7,10,ticksend,6
-0x0113,16,movetokafra,5:12
-0x0116,2,closekafra,0
-0x0190,26,movefromkafra,10:22
-0x0193,9,actionrequest,3:8
+// packet_ver: 8
+// 0x0072,14,dropitem,5:12
+// 0x007e,33,wanttoconnection,12:18:24:28:32
+// 0x0085,20,useskilltoid,7:12:16
+// 0x0089,15,getcharnamerequest,11
+// 0x008c,23,useskilltopos,3:6:17:21
+// 0x0094,10,takeitem,6
+// 0x009b,6,walktoxy,3
+// 0x009f,13,changedir,5:12
+// 0x00a2,103,useskilltopos,3:6:17:21:23
+// 0x00a7,12,solvecharname,8
+// 0x00f3,-1,globalmessage,2:4
+// 0x00f5,17,useitem,6:12
+// 0x00f7,10,ticksend,6
+// 0x0113,16,movetokafra,5:12
+// 0x0116,2,closekafra,0
+// 0x0190,26,movefromkafra,10:22
+// 0x0193,9,actionrequest,3:8
 
 //2004-08-09kRO
-packet_ver: 9
-0x0072,17,dropitem,8:15
+// packet_ver: 9
+// 0x0072,17,dropitem,8:15
 //9, +12, +7, +4, +4
-0x007e,37,wanttoconnection,9:21:28:32:36
-0x0085,26,useskilltoid,11:18:22
-0x0089,12,getcharnamerequest,8
-0x008c,40,useskilltopos,5:15:29:38
-0x0094,13,takeitem,9
-0x009b,15,walktoxy,12
-0x009f,12,changedir,7:11
-0x00a2,120,useskilltopos,5:15:29:38:40
-0x00a7,11,solvecharname,7
-0x00f5,24,useitem,9:20
-0x00f7,13,ticksend,9
-0x0113,23,movetokafra,5:19
-0x0190,26,movefromkafra,11:22
-0x0193,18,actionrequest,7:17
+// 0x007e,37,wanttoconnection,9:21:28:32:36
+// 0x0085,26,useskilltoid,11:18:22
+// 0x0089,12,getcharnamerequest,8
+// 0x008c,40,useskilltopos,5:15:29:38
+// 0x0094,13,takeitem,9
+// 0x009b,15,walktoxy,12
+// 0x009f,12,changedir,7:11
+// 0x00a2,120,useskilltopos,5:15:29:38:40
+// 0x00a7,11,solvecharname,7
+// 0x00f5,24,useitem,9:20
+// 0x00f7,13,ticksend,9
+// 0x0113,23,movetokafra,5:19
+// 0x0190,26,movefromkafra,11:22
+// 0x0193,18,actionrequest,7:17
 
 //2004-08-16aSakexe
-0x020f,0
-0x0210,0
-0x0211,0
-0x0212,26
-0x0213,26
-0x0214,42
+// 0x020f,0
+// 0x0210,0
+// 0x0211,0
+// 0x0212,26
+// 0x0213,26
+// 0x0214,42
 
 //2004-08-17aSakexe
-0x020f,10
-0x0210,22
+// 0x020f,10
+// 0x0210,22
 
 //2004-09-06aSakexe
-packet_ver: 10
+// packet_ver: 10
 //0x0072,20,useitem,9:20
-0x007e,19,movetokafra,3:15
-0x0085,23,actionrequest,9:22
-0x0089,9,walktoxy,6
-0x008c,105,useskilltopos,10:14:18:23:25
-0x0094,17,dropitem,6:15
-0x009b,14,getcharnamerequest,10
-0x009f,-1,globalmessage,2:4
-0x00a2,14,solvecharname,10
-0x00a7,25,useskilltopos,10:14:18:23
-0x00f3,10,changedir,4:9
+// 0x007e,19,movetokafra,3:15
+// 0x0085,23,actionrequest,9:22
+// 0x0089,9,walktoxy,6
+// 0x008c,105,useskilltopos,10:14:18:23:25
+// 0x0094,17,dropitem,6:15
+// 0x009b,14,getcharnamerequest,10
+// 0x009f,-1,globalmessage,2:4
+// 0x00a2,14,solvecharname,10
+// 0x00a7,25,useskilltopos,10:14:18:23
+// 0x00f3,10,changedir,4:9
 //7, +7, +10, +4, +6
-0x00f5,34,wanttoconnection,7:15:25:29:33
-0x00f7,2,closekafra,0
-0x0113,11,takeitem,7
-0x0116,11,ticksend,7
-0x0190,22,useskilltoid,9:15:18
-0x0193,17,movefromkafra,3:13
+// 0x00f5,34,wanttoconnection,7:15:25:29:33
+// 0x00f7,2,closekafra,0
+// 0x0113,11,takeitem,7
+// 0x0116,11,ticksend,7
+// 0x0190,22,useskilltoid,9:15:18
+// 0x0193,17,movefromkafra,3:13
 
 //2004-09-21aSakexe by Sara
-packet_ver: 11
-0x0072,18,useitem,10:14
-0x007e,25,movetokafra,6:21
-0x0085,9,actionrequest,3:8
-0x0089,14,walktoxy,11
-0x008c,109,useskilltopos,16:20:23:27:29
-0x0094,19,dropitem,12:17
-0x00a2,10,solvecharname,6
-0x00a7,29,useskilltopos,6:20:23:27
-0x00f3,18,changedir,8:17
-0x00f5,32,wanttoconnection,10:17:23:27:31
-0x009b,10,getcharnamerequest,6
-0x0113,14,takeitem,10
-0x0116,14,ticksend,10
-0x0190,14,useskilltoid,4:7:10
-0x0193,12,movefromkafra,4:8
+// packet_ver: 11
+// 0x0072,18,useitem,10:14
+// 0x007e,25,movetokafra,6:21
+// 0x0085,9,actionrequest,3:8
+// 0x0089,14,walktoxy,11
+// 0x008c,109,useskilltopos,16:20:23:27:29
+// 0x0094,19,dropitem,12:17
+// 0x00a2,10,solvecharname,6
+// 0x00a7,29,useskilltopos,6:20:23:27
+// 0x00f3,18,changedir,8:17
+// 0x00f5,32,wanttoconnection,10:17:23:27:31
+// 0x009b,10,getcharnamerequest,6
+// 0x0113,14,takeitem,10
+// 0x0116,14,ticksend,10
+// 0x0190,14,useskilltoid,4:7:10
+// 0x0193,12,movefromkafra,4:8
 
 //2004-10-11aSakexe by Sara
-packet_ver: 12
-0x0072,17,useitem,6:13
-0x007e,16,movetokafra,5:12
-0x0089,6,walktoxy,3
-0x008c,103,useskilltopos,2:6:17:21:23
-0x0094,14,dropitem,5:12
-0x009b,15,getcharnamerequest,11
-0x00a2,12,solvecharname,8
-0x00a7,23,useskilltopos,3:6:17:21
-0x00f3,13,changedir,5:12
-0x00f5,33,wanttoconnection,12:18:24:28:32
-0x0113,10,takeitem,6
-0x0116,10,ticksend,6
-0x0190,20,useskilltoid,7:12:16
-0x0193,26,movefromkafra,10:22
+// packet_ver: 12
+// 0x0072,17,useitem,6:13
+// 0x007e,16,movetokafra,5:12
+// 0x0089,6,walktoxy,3
+// 0x008c,103,useskilltopos,2:6:17:21:23
+// 0x0094,14,dropitem,5:12
+// 0x009b,15,getcharnamerequest,11
+// 0x00a2,12,solvecharname,8
+// 0x00a7,23,useskilltopos,3:6:17:21
+// 0x00f3,13,changedir,5:12
+// 0x00f5,33,wanttoconnection,12:18:24:28:32
+// 0x0113,10,takeitem,6
+// 0x0116,10,ticksend,6
+// 0x0190,20,useskilltoid,7:12:16
+// 0x0193,26,movefromkafra,10:22
 
 //2004-10-25aSakexe by Sara
-packet_ver: 13
-0x0072,13,useitem,5:9
-0x007e,13,movetokafra,6:9
-0x0085,15,actionrequest,4:14
-0x008c,108,useskilltopos,6:9:23:26:28
-0x0094,12,dropitem,6:10
-0x009b,10,getcharnamerequest,6
-0x00a2,16,solvecharname,12
-0x00a7,28,useskilltopos,6:9:23:26
-0x00f3,15,changedir,6:14
-0x00f5,29,wanttoconnection,5:14:20:24:28
-0x0113,9,takeitem,5
-0x0116,9,ticksend,5
-0x0190,26,useskilltoid,4:10:22
-0x0193,22,movefromkafra,12:18
+// packet_ver: 13
+// 0x0072,13,useitem,5:9
+// 0x007e,13,movetokafra,6:9
+// 0x0085,15,actionrequest,4:14
+// 0x008c,108,useskilltopos,6:9:23:26:28
+// 0x0094,12,dropitem,6:10
+// 0x009b,10,getcharnamerequest,6
+// 0x00a2,16,solvecharname,12
+// 0x00a7,28,useskilltopos,6:9:23:26
+// 0x00f3,15,changedir,6:14
+// 0x00f5,29,wanttoconnection,5:14:20:24:28
+// 0x0113,9,takeitem,5
+// 0x0116,9,ticksend,5
+// 0x0190,26,useskilltoid,4:10:22
+// 0x0193,22,movefromkafra,12:18
 
 //2004-11-01aSakexe by Sara
-packet_ver: 14
-0x0215,6
-0x0143,23,npcamountinput,2:6
-0x0145,19
+// packet_ver: 14
+// 0x0215,6
+// 0x0143,23,npcamountinput,2:6
+// 0x0145,19
 //0x01f9,6,adopt,5
 
 //2004-12-06aSakexe
-packet_ver: 15
-0x0190,15,useitem,3:11
-0x0094,14,movetokafra,4:10
-0x009f,18,actionrequest,6:17
-0x00a7,7,walktoxy,4
-0x007e,30,useskilltopos,4:9:22:28
-0x0116,12,dropitem,4:10
-0x008c,13,getcharnamerequest,9
-0x0085,-1,globalmessage,2:4
-0x00f7,14,solvecharname,10
-0x0113,110,useskilltopos,4:9:22:28:30
-0x00f3,8,changedir,3:7
-0x00f5,29,wanttoconnection,3:10:20:24:28
-0x00a2,7,takeitem,3
-0x0089,7,ticksend,3
-0x0072,22,useskilltoid,8:12:18
-0x0193,21,movefromkafra,4:17
-0x009b,2,closekafra,0
-0x0222,6
-0x0221,-1
-0x021d,6
-0x0223,8
+// packet_ver: 15
+// 0x0190,15,useitem,3:11
+// 0x0094,14,movetokafra,4:10
+// 0x009f,18,actionrequest,6:17
+// 0x00a7,7,walktoxy,4
+// 0x007e,30,useskilltopos,4:9:22:28
+// 0x0116,12,dropitem,4:10
+// 0x008c,13,getcharnamerequest,9
+// 0x0085,-1,globalmessage,2:4
+// 0x00f7,14,solvecharname,10
+// 0x0113,110,useskilltopos,4:9:22:28:30
+// 0x00f3,8,changedir,3:7
+// 0x00f5,29,wanttoconnection,3:10:20:24:28
+// 0x00a2,7,takeitem,3
+// 0x0089,7,ticksend,3
+// 0x0072,22,useskilltoid,8:12:18
+// 0x0193,21,movefromkafra,4:17
+// 0x009b,2,closekafra,0
+// 0x0222,6
+// 0x0221,-1
+// 0x021d,6
+// 0x0223,8
 
 //2005-01-10bSakexe by Sara
-packet_ver: 16
+// packet_ver: 16
 0x009b,32,wanttoconnection,3:12:23:27:31
 0x0089,9,ticksend,5
 0x00a7,13,walktoxy,10
@@ -631,5 +643,7 @@ packet_ver: 16
 0x0072,26,useskilltoid,8:16:22
 0x007e,114,useskilltopos,9:18:22:32:34
 0x00a2,11,solvecharname,7
+0x0143,10,npcamountinput,2:6
 
-packet_ver: 17
+// packet_ver: 17
+// Add new packets here

+ 1 - 1
db/skill_cast_db.txt

@@ -32,7 +32,7 @@
 35,0,1000,0,0	//AL_CURE#キュアー#
 
 45,0,0,60000:80000:100000:120000:140000:160000:180000:200000:220000:240000,0	//AC_CONCENTRATION#集中力向上#
-46,0,1500,100,0	//AC_DOUBLE
+46,0,-300,100,0	//AC_DOUBLE
 47,0,1500,100,0	//AC_SHOWER
 
 51,0,0,30000:60000:90000:120000:150000:180000:210000:240000:270000:300000,0	//TF_HIDING#ハイディング#

+ 124 - 46
npc/mobs/fields/yuno.txt

@@ -3,58 +3,136 @@
 //===== By: ==================================================
 //= Athena (1.0)
 //===== Current Version: =====================================
-//= 1.1
+//= 1.3
 //===== Compatible With: =====================================
 //= Any Athena Version
 //===== Additional Comments: =================================
 //= 1.1 fixed tabs, names [Lupus]
+//= 1.2 New/Better Spawn [Muad_Dib]
+//= 1.3 Fix Up [Darkchild]
 //============================================================
 
-//(yuno_fild04.gat)*
-yuno_fild04.gat,0,0,0,0	monster	Goat	1372,40,0,0,0
-yuno_fild04.gat,0,0,0,0	monster	Sleeper	1386,5,0,0,0
-yuno_fild04.gat,0,0,0,0	monster	The Paper	1375,3,0,0,0
-yuno_fild04.gat,0,0,0,0	monster	Geographer	1368,20,0,0,0
-yuno_fild04.gat,0,0,0,0	monster	Driller	1380,10,0,0,0
-yuno_fild04.gat,0,0,0,0	monster	Poring	1002,20,0,0,0
+//========================================================================================
+// - Yuno Field 01
+//========================================================================================
+
+yuno_fild01.gat,0,0,0,0	monster	Poring	1002,55,0,0,0
+yuno_fild01.gat,0,0,0,0	monster	Poporing	1031,35,0,0,0
+yuno_fild01.gat,0,0,0,0	monster	Dustiness	1114,25,0,0,0
+yuno_fild01.gat,0,0,0,0	monster	Green Plant	1080,10,180000,90000,1
+yuno_fild01.gat,0,0,0,0	monster	Red Plant	1078,15,180000,90000,1
+yuno_fild01.gat,0,0,0,0	monster	Shining Plant	1083,5,1800000,900000,1
+yuno_fild01.gat,0,0,0,0	monster	Yellow Plant	1081,20,360000,180000,1
+
+//========================================================================================
+// - Yuno Field 02
+//========================================================================================
+
+yuno_fild02.gat,0,0,0,0	monster	Sageworm	1281,5,0,0,0
+yuno_fild02.gat,0,0,0,0	monster	Dustiness	1114,15,0,0,0
+yuno_fild02.gat,0,0,0,0	monster	Kind of Beetle	1494,15,0,0,0
+yuno_fild02.gat,0,0,0,0	monster	Horn		1128,35,0,0,0
+yuno_fild02.gat,0,0,0,0	monster	Stainer	1174,25,0,0,0
+yuno_fild02.gat,0,0,0,0	monster	Wild Rose	1261,15,0,0,0
+yuno_fild02.gat,0,0,0,0	monster	Red Plant	1078,15,180000,90000,1
+yuno_fild02.gat,0,0,0,0	monster	Yellow Plant	1081,20,360000,180000,1
+yuno_fild02.gat,0,0,0,0	monster	Green Plant	1080,15,180000,90000,1
+
+//========================================================================================
+// - Yuno Field 03
+//========================================================================================
+
+yuno_fild03.gat,0,0,0,0	monster	Drops		1113,30,0,0,0
+yuno_fild03.gat,0,0,0,0	monster	Poring	1002,40,0,0,0
+yuno_fild03.gat,0,0,0,0	monster	Sidewinder	1037,5,0,0,0
+yuno_fild03.gat,0,0,0,0	monster	Poporing	1031,20,0,0,0
+yuno_fild03.gat,0,0,0,0	monster	Marin		1242,20,0,0,0
+yuno_fild03.gat,0,0,0,0	monster	Geographer	1368,15,0,0,0
+yuno_fild03.gat,0,0,0,0	monster	Archangeling	1388,1,3600000,1800000,1
+yuno_fild03.gat,0,0,0,0	monster	Red Plant	1078,15,180000,90000,1
+yuno_fild03.gat,0,0,0,0	monster	Green Plant	1080,50,180000,90000,1
+yuno_fild03.gat,0,0,0,0	monster	Yellow Plant	1081,20,360000,180000,1
+
+//========================================================================================
+// - Yuno Field 04
+//========================================================================================
+
+yuno_fild04.gat,0,0,0,0	monster	Poring	1002,50,0,0,0
+yuno_fild04.gat,0,0,0,0	monster	Pupa		1008,15,0,0,0
+yuno_fild04.gat,0,0,0,0	monster	Drops		1113,30,0,0,0
+yuno_fild04.gat,0,0,0,0	monster	Condor	1009,15,0,0,0
+yuno_fild04.gat,0,0,0,0	monster	Creamy	1018,10,0,0,0
 yuno_fild04.gat,0,0,0,0	monster	Green Plant	1080,10,180000,90000,1
 yuno_fild04.gat,0,0,0,0	monster	Red Plant	1078,10,180000,90000,1
 yuno_fild04.gat,0,0,0,0	monster	Yellow Plant	1081,10,360000,180000,1
-yuno_fild04.gat,0,0,0,0	monster	Harpy	1376,1,0,0,0
-
-//(yuno_fild03.gat)*
-yuno_fild03.gat,0,0,0,0	monster	Goat	1372,60,0,0,0
-yuno_fild03.gat,0,0,0,0	monster	Sleeper	1386,30,0,0,0
-yuno_fild03.gat,0,0,0,0	monster	The Paper	1375,3,0,0,0
-yuno_fild03.gat,0,0,0,0	monster	Geographer	1368,20,0,0,0
-yuno_fild03.gat,0,0,0,0	monster	Demon Pungus	1378,30,0,0,0
-yuno_fild03.gat,0,0,0,0	monster	Red Plant	1078,15,180000,90000,1
-yuno_fild03.gat,0,0,0,0	monster	Shining Plant	1083,2,1800000,900000,1
-yuno_fild03.gat,0,0,0,0	monster	Blue Plant	1079,4,360000,180000,1
-yuno_fild03.gat,0,0,0,0	monster	Yellow Plant	1081,20,360000,180000,1
-yuno_fild03.gat,0,0,0,0	monster	Harpy	1376,2,0,0,0
-
-//(yuno_fild02.gat)*
-yuno_fild02.gat,0,0,0,0	monster	Sleeper	1386,10,0,0,0
-yuno_fild02.gat,0,0,0,0	monster	Grand Peco	1369,70,0,0,0
-yuno_fild02.gat,0,0,0,0	monster	The Paper	1375,1,0,0,0
-yuno_fild02.gat,0,0,0,0	monster	Geographer	1368,20,0,0,0
-yuno_fild02.gat,0,0,0,0	monster	Driller	1380,30,0,0,0
-yuno_fild02.gat,0,0,0,0	monster	Dustiness	1114,20,0,0,0
-yuno_fild02.gat,0,0,0,0	monster	Poring	1002,20,0,0,0
-yuno_fild02.gat,0,0,0,0	monster	Red Plant	1078,20,180000,90000,1
-yuno_fild02.gat,0,0,0,0	monster	Shining Plant	1083,1,1800000,900000,1
-yuno_fild02.gat,0,0,0,0	monster	Blue Plant	1079,3,360000,180000,1
-yuno_fild02.gat,0,0,0,0	monster	Yellow Plant	1081,20,360000,180000,1
-yuno_fild02.gat,0,0,0,0	monster	Archangeling	1388,1,3600000,1800000,1
-
-//(yuno_fild01.gat)*
-yuno_fild01.gat,0,0,0,0	monster	Grand Peco	1369,3,0,0,0
-yuno_fild01.gat,0,0,0,0	monster	Dustiness	1114,50,0,0,0
-yuno_fild01.gat,0,0,0,0	monster	Poporing	1031,20,0,0,0
-yuno_fild01.gat,0,0,0,0	monster	Poring	1002,20,0,0,0
-yuno_fild01.gat,0,0,0,0	monster	Green Plant	1080,20,180000,90000,1
-yuno_fild01.gat,0,0,0,0	monster	Red Plant	1078,15,180000,90000,1
-yuno_fild01.gat,0,0,0,0	monster	Shining Plant	1083,3,1800000,900000,1
-yuno_fild01.gat,0,0,0,0	monster	Blue Plant	1079,2,360000,180000,1
-yuno_fild01.gat,0,0,0,0	monster	Yellow Plant	1081,23,360000,180000,1
+
+//========================================================================================
+// - Yuno Field 05
+//========================================================================================
+
+yuno_fild05.gat,0,0,0,0	monster	Geographer	1368,20,0,0,0
+yuno_fild05.gat,0,0,0,0	monster	Goat		1372,5,0,0,0
+yuno_fild05.gat,0,0,0,0	monster	Demon Pungus	1378,20,0,0,0
+yuno_fild05.gat,0,0,0,0	monster	Sleeper	1386,45,0,0,0
+yuno_fild05.gat,0,0,0,0	monster	The Paper	1375,15,0,0,0
+yuno_fild05.gat,0,0,0,0	monster	Green Plant	1080,5,180000,90000,1
+yuno_fild05.gat,0,0,0,0	monster	Yellow Plant	1081,10,360000,180000,1
+yuno_fild05.gat,0,0,0,0	monster	Red Plant	1078,5,180000,90000,1
+
+//========================================================================================
+// - Yuno Field 07
+//========================================================================================
+
+yuno_fild07.gat,0,0,0,0	monster	Geographer	1368,20,0,0,0
+yuno_fild07.gat,0,0,0,0	monster	Goat		1372,60,0,0,0
+yuno_fild07.gat,0,0,0,0	monster	Green Plant	1080,10,180000,90000,1
+yuno_fild07.gat,0,0,0,0	monster	Red Plant	1078,10,180000,90000,1
+yuno_fild07.gat,0,0,0,0	monster	Yellow Plant	1081,15,360000,180000,1
+
+//========================================================================================
+// - Yuno Field 08
+//========================================================================================
+
+yuno_fild08.gat,0,0,0,0	monster	Grand Peco	1369,20,0,0,0
+yuno_fild08.gat,0,0,0,0	monster	Dustiness	1114,30,0,0,0
+yuno_fild08.gat,0,0,0,0	monster	Geographer	1368,20,0,0,0
+yuno_fild08.gat,0,0,0,0	monster	Wild Rose	1261,15,0,0,0
+yuno_fild08.gat,0,0,0,0	monster	Red Plant	1078,15,180000,90000,1
+yuno_fild08.gat,0,0,0,0	monster	Yellow Plant	1081,20,360000,180000,1
+yuno_fild08.gat,0,0,0,0	monster	Green Plant	1080,10,180000,90000,1
+
+//========================================================================================
+// - Yuno Field 09
+//========================================================================================
+
+yuno_fild09.gat,0,0,0,0	monster	Gargoyle	1253,10,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Dustiness	1114,20,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Goblin	1122,10,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Goblin	1123,5,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Goblin	1124,10,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Goblin	1125,5,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Goblin	1126,5,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Horn		1128,25,0,0,0
+yuno_fild09.gat,0,0,0,0	monster	Red Plant	1078,10,180000,90000,1
+yuno_fild09.gat,0,0,0,0	monster	Yellow Plant	1081,15,360000,180000,1
+yuno_fild09.gat,0,0,0,0	monster	Green Plant	1080,15,180000,90000,1
+
+//========================================================================================
+// - Yuno Field 11
+//========================================================================================
+
+yuno_fild11.gat,0,0,0,0	monster	Sleeper	1386,55,0,0,0
+yuno_fild11.gat,0,0,0,0	monster	Geographer	1368,20,0,0,0
+yuno_fild11.gat,0,0,0,0	monster	Red Plant	1078,10,180000,90000,1
+yuno_fild11.gat,0,0,0,0	monster	Green Plant	1080,10,180000,90000,1
+yuno_fild11.gat,0,0,0,0	monster	Yellow Plant	1081,15,360000,180000,1
+
+//========================================================================================
+// - Yuno Field 12
+//========================================================================================
+
+yuno_fild12.gat,0,0,0,0	monster	Dustiness	1114,35,0,0,0
+yuno_fild12.gat,0,0,0,0	monster	Demon Pungus	1378,20,0,0,0
+yuno_fild12.gat,0,0,0,0	monster	Green Plant	1080,10,180000,90000,1
+yuno_fild12.gat,0,0,0,0	monster	Red Plant	1078,5,180000,90000,1
+yuno_fild12.gat,0,0,0,0	monster	Yellow Plant	1081,10,360000,180000,1

+ 0 - 3
sql-files/database.sql

@@ -1,6 +1,3 @@
-DROP DATABASE erag;
-CREATE DATABASE erag;
-USE erag;
 CREATE TABLE `item_db` (
   `id` smallint(5) unsigned NOT NULL default '0',
   `name_english` varchar(24) NOT NULL default '',

+ 0 - 2
sql-files/mail.sql

@@ -1,5 +1,3 @@
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `ragnarok`;
-USE `ragnarok`;
 CREATE TABLE `mail` (
   `message_id` int(11) NOT NULL auto_increment,
   `to_account_id` int(11) NOT NULL default '0',

+ 61 - 59
src/char/char.c

@@ -166,7 +166,7 @@ int char_log(char *fmt, ...) {
 //-----------------------------------------------------
 // Function to suppress control characters in a string.
 //-----------------------------------------------------
-int remove_control_chars(unsigned char *str) {
+int remove_control_chars(char *str) {
 	int i;
 	int change = 0;
 
@@ -244,7 +244,7 @@ int mmo_friends_list_data_str(char *str, struct mmo_charstatus *p) {
 	int i;
 	char *str_p = str;
 	str_p += sprintf(str_p, "%d", p->char_id);
-	
+
 	for (i=0;i<20;i++)
 	{
 		str_p += sprintf(str_p, ",%d,%s", p->friend_id[i],p->friend_name[i]);
@@ -575,16 +575,16 @@ int parse_friend_txt(struct mmo_charstatus *p)
 	char line[1024];
 	int i,cid=0,temp[20];
 	FILE *fp;
-	
+
 	// Open the file and look for the ID
 	fp = fopen(friends_txt, "r");
 
 	if(fp == NULL)
 		return 1;
-	
+
 
 	while(fgets(line, sizeof(line)-1, fp)) {
-		
+
 		if(line[0] == '/' && line[1] == '/')
 			continue;
 
@@ -612,7 +612,7 @@ int parse_friend_txt(struct mmo_charstatus *p)
 		if (cid == p->char_id)
 			break;
 	}
-	
+
 	// No register of friends list
 	if (cid == 0) {
 		fclose(fp);
@@ -638,12 +638,12 @@ int mmo_char_init(void) {
 	FILE *fp;
 
 	char_max = 256;
-	char_dat = calloc(sizeof(struct mmo_charstatus) * 256, 1);
+	char_dat = (struct mmo_charstatus*)aCalloc(sizeof(struct mmo_charstatus) * 256, 1);
 	if (!char_dat) {
 		printf("out of memory: mmo_char_init (calloc of char_dat).\n");
 		exit(1);
 	}
-	online_chars = calloc(sizeof(struct online_chars) * 256, 1);
+	online_chars = (struct online_chars*)aCalloc(sizeof(struct online_chars) * 256, 1);
 	if (!online_chars) {
 		printf("out of memory: mmo_char_init (calloc of online_chars).\n");
 		exit(1);
@@ -683,13 +683,13 @@ int mmo_char_init(void) {
 
 		if (char_num >= char_max) {
 			char_max += 256;
-			char_dat = realloc(char_dat, sizeof(struct mmo_charstatus) * char_max);
+			char_dat = (struct mmo_charstatus*)aRealloc(char_dat, sizeof(struct mmo_charstatus) * char_max);
 			if (!char_dat) {
 				printf("Out of memory: mmo_char_init (realloc of char_dat).\n");
 				char_log("Out of memory: mmo_char_init (realloc of char_dat)." RETCODE);
 				exit(1);
 			}
-			online_chars = realloc(online_chars, sizeof(struct online_chars) * char_max);
+			online_chars = (struct online_chars*)aRealloc(online_chars, sizeof(struct online_chars) * char_max);
 			if (!online_chars) {
 				printf("Out of memory: mmo_char_init (realloc of online_chars).\n");
 				char_log("Out of memory: mmo_char_init (realloc of online_chars)." RETCODE);
@@ -703,10 +703,10 @@ int mmo_char_init(void) {
 		}
 
 		ret = mmo_char_fromstr(line, &char_dat[char_num]);
-		
+
 		// Initialize friends list
 		parse_friend_txt(&char_dat[char_num]);  // Grab friends for the character
-		
+
 		if (ret > 0) { // negative value or zero for errors
 			if (char_dat[char_num].char_id >= char_id_count)
 				char_id_count = char_dat[char_num].char_id + 1;
@@ -769,7 +769,7 @@ void mmo_char_sync(void) {
 	int i, j, k;
 	int lock;
 	FILE *fp,*f_fp;
-	int id[char_num];
+	int *id = (int *) aMalloc(sizeof(int) * char_num);
 
 	// Sorting before save (by [Yor])
 	for(i = 0; i < char_num; i++) {
@@ -825,9 +825,11 @@ void mmo_char_sync(void) {
 		mmo_friends_list_data_str(f_line, &char_dat[id[i]]);
 		fprintf(f_fp, "%s" RETCODE, f_line);
 	}
-	
+
 	lock_fclose(f_fp, friends_txt, &lock);
-	
+
+	aFree(id);
+
 	return;
 }
 
@@ -847,7 +849,7 @@ int make_new_char(int fd, unsigned char *dat) {
 	int i, j;
 	struct char_session_data *sd;
 
-	sd = session[fd]->session_data;
+	sd = (struct char_session_data*)session[fd]->session_data;
 
 	// remove control characters from the name
 	dat[23] = '\0';
@@ -921,13 +923,13 @@ int make_new_char(int fd, unsigned char *dat) {
 
 	if (char_num >= char_max) {
 		char_max += 256;
-		char_dat = realloc(char_dat, sizeof(struct mmo_charstatus) * char_max);
+		char_dat = (struct mmo_charstatus*)aRealloc(char_dat, sizeof(struct mmo_charstatus) * char_max);
 		if (!char_dat) {
 			printf("Out of memory: make_new_char (realloc of char_dat).\n");
 			char_log("Out of memory: make_new_char (realloc of char_dat)." RETCODE);
 			exit(1);
 		}
-		online_chars = realloc(online_chars, sizeof(struct online_chars) * char_max);
+		online_chars = (struct online_chars*)aRealloc(online_chars, sizeof(struct online_chars) * char_max);
 		if (!online_chars) {
 			printf("Out of memory: make_new_char (realloc of online_chars).\n");
 			char_log("Out of memory: make_new_char (realloc of online_chars)." RETCODE);
@@ -998,8 +1000,8 @@ int make_new_char(int fd, unsigned char *dat) {
 //----------------------------------------------------
 // This function return the name of the job (by [Yor])
 //----------------------------------------------------
-char * job_name(int class) {
-	switch (class) {
+char * job_name(int class_) {
+	switch (class_) {
 	case 0:    return "Novice";
 	case 1:    return "Swordsman";
 	case 2:    return "Mage";
@@ -1550,7 +1552,7 @@ int disconnect_player(int accound_id) {
 
 	// disconnect player if online on char-server
 	for(i = 0; i < fd_max; i++) {
-		if (session[i] && (sd = session[i]->session_data)) {
+		if (session[i] && (sd = (struct char_session_data*)session[i]->session_data)) {
 			if (sd->account_id == accound_id) {
 				session[i]->eof = 1;
 				return 1;
@@ -1612,7 +1614,7 @@ int parse_tologin(int fd) {
 		return 0;
 	}
 
-	sd = session[fd]->session_data;
+	sd = (struct char_session_data*)session[fd]->session_data;
 
 	while(RFIFOREST(fd) >= 2) {
 //		printf("parse_tologin: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
@@ -1645,7 +1647,7 @@ int parse_tologin(int fd) {
 				return 0;
 //			printf("parse_tologin 2713 : %d\n", RFIFOB(fd,6));
 			for(i = 0; i < fd_max; i++) {
-				if (session[i] && (sd = session[i]->session_data) && sd->account_id == RFIFOL(fd,2)) {
+				if (session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->account_id == RFIFOL(fd,2)) {
 					if (RFIFOB(fd,6) != 0) {
 						WFIFOW(i,0) = 0x6c;
 						WFIFOB(i,2) = 0x42;
@@ -1683,7 +1685,7 @@ int parse_tologin(int fd) {
 			if (RFIFOREST(fd) < 50)
 				return 0;
 			for(i = 0; i < fd_max; i++) {
-				if (session[i] && (sd = session[i]->session_data)) {
+				if (session[i] && (sd = (struct char_session_data*)session[i]->session_data)) {
 					if (sd->account_id == RFIFOL(fd,2)) {
 						memcpy(sd->email, RFIFOP(fd,6), 40);
 						if (e_mail_check(sd->email) == 0)
@@ -1891,7 +1893,7 @@ int parse_tologin(int fd) {
 							int j, k;
 							struct char_session_data *sd2;
 							for (j = 0; j < fd_max; j++) {
-								if (session[j] && (sd2 = session[j]->session_data) &&
+								if (session[j] && (sd2 = (struct char_session_data*)session[j]->session_data) &&
 									sd2->account_id == char_dat[char_num-1].account_id) {
 									for (k = 0; k < 9; k++) {
 										if (sd2->found_char[k] == char_num-1) {
@@ -1946,8 +1948,8 @@ int parse_tologin(int fd) {
 		  {
 			char buf[32000];
 			if (gm_account != NULL)
-				free(gm_account);
-			gm_account = calloc(sizeof(struct gm_account) * ((RFIFOW(fd,2) - 4) / 5), 1);
+				aFree(gm_account);
+			gm_account = (struct gm_account*)aCalloc(sizeof(struct gm_account) * ((RFIFOW(fd,2) - 4) / 5), 1);
 			GM_num = 0;
 			for (i = 4; i < RFIFOW(fd,2); i = i + 5) {
 				gm_account[GM_num].account_id = RFIFOL(fd,i);
@@ -2158,7 +2160,7 @@ int parse_frommap(int fd) {
 				if (j == online_players_max) {
 					// create 256 new slots
 					online_players_max += 256;
-					online_chars = realloc(online_chars, sizeof(struct online_chars) * online_players_max);
+					online_chars = (struct online_chars*)aRealloc(online_chars, sizeof(struct online_chars) * online_players_max);
 					if (!online_chars) {
 						printf("out of memory: parse_frommap - online_chars (realloc).\n");
 						exit(1);
@@ -2515,7 +2517,7 @@ int parse_char(int fd) {
 		return 0;
 	}
 
-	sd = session[fd]->session_data;
+	sd = (struct char_session_data*)session[fd]->session_data;
 
 	while (RFIFOREST(fd) >= 2) {
 		cmd = RFIFOW(fd,0);
@@ -2539,7 +2541,7 @@ int parse_char(int fd) {
 //		if (sd == NULL && cmd != 0x65 && cmd != 0x20b && cmd != 0x187 &&
 //					 cmd != 0x2af8 && cmd != 0x7530 && cmd != 0x7532)
 //			cmd = 0xffff;	// パケットダンプを表示させる
-		
+
 		switch(cmd){
 		case 0x20b:	//20040622暗号化ragexe対応
 			if (RFIFOREST(fd) < 19)
@@ -2557,7 +2559,7 @@ int parse_char(int fd) {
 			else
 				printf("Account Logged On; Account ID: %d.\n", RFIFOL(fd,2));
 			if (sd == NULL) {
-				sd = session[fd]->session_data = calloc(sizeof(struct char_session_data), 1);
+				sd = session[fd]->session_data = (struct char_session_data*)aCalloc(sizeof(struct char_session_data), 1);
 				memset(sd, 0, sizeof(struct char_session_data));
 				memcpy(sd->email, "no mail", 40); // put here a mail without '@' to refuse deletion if we don't receive the e-mail
 				sd->connect_until_time = 0; // unknow or illimited (not displaying on map-server)
@@ -2837,7 +2839,7 @@ int parse_char(int fd) {
 									int j, k;
 									struct char_session_data *sd2;
 									for (j = 0; j < fd_max; j++) {
-										if (session[j] && (sd2 = session[j]->session_data) &&
+										if (session[j] && (sd2 = (struct char_session_data*)session[j]->session_data) &&
 											sd2->account_id == char_dat[char_num-1].account_id) {
 											for (k = 0; k < 9; k++) {
 												if (sd2->found_char[k] == char_num-1) {
@@ -2947,29 +2949,29 @@ int parse_char(int fd) {
 // Console Command Parser [Wizputer]
 int parse_console(char *buf) {
     char *type,*command;
-    
-    type = (char *)malloc(64);
-    command = (char *)malloc(64);
-    
+
+    type = (char *)aMalloc(64);
+    command = (char *)aMalloc(64);
+
     memset(type,0,64);
     memset(command,0,64);
-    
+
     printf("Console: %s\n",buf);
-    
+
     if ( sscanf(buf, "%[^:]:%[^\n]", type , command ) < 2 )
         sscanf(buf,"%[^\n]",type);
-    
+
     printf("Type of command: %s || Command: %s \n",type,command);
-    
-    if(buf) free(buf);
-    if(type) free(type);
-    if(command) free(command);
-    
+
+    if(buf) aFree(buf);
+    if(type) aFree(type);
+    if(command) aFree(command);
+
     return 0;
 }
 
 // 全てのMAPサーバーにデータ送信(送信したmap鯖の数を返す)
-int mapif_sendall(unsigned char *buf, unsigned int len) {
+int mapif_sendall(char *buf, unsigned int len) {
 	int i, c;
 
 	c = 0;
@@ -2985,7 +2987,7 @@ int mapif_sendall(unsigned char *buf, unsigned int len) {
 }
 
 // 自分以外の全てのMAPサーバーにデータ送信(送信したmap鯖の数を返す)
-int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len) {
+int mapif_sendallwos(int sfd, char *buf, unsigned int len) {
 	int i, c;
 
 	c = 0;
@@ -3000,7 +3002,7 @@ int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len) {
 	return c;
 }
 // MAPサーバーにデータ送信(map鯖生存確認有り)
-int mapif_send(int fd, unsigned char *buf, unsigned int len) {
+int mapif_send(int fd, char *buf, unsigned int len) {
 	int i;
 
 	if (fd >= 0) {
@@ -3349,19 +3351,19 @@ void do_final(void) {
 	}
 
 	create_online_files();
-	if(online_chars) free(online_chars);
+	if(online_chars) aFree(online_chars);
 
 	mmo_char_sync();
 	inter_save();
 
-	if(gm_account) free(gm_account);
-	if(char_dat) free(char_dat);
+	if(gm_account) aFree(gm_account);
+	if(char_dat) aFree(char_dat);
 
 	delete_session(login_fd);
 	delete_session(char_fd);
 
 	for(i = 0; i < fd_max; i++)
-		if(session[i] != NULL) free(session[i]);
+		if(session[i] != NULL) aFree(session[i]);
 
 	char_log("----End of char-server (normal end with closing of all files)." RETCODE);
 }
@@ -3377,14 +3379,14 @@ int do_init(int argc, char **argv) {
 		// moved behind char_config_read in case we changed the filename [celest]
 		char_log("The char-server starting..." RETCODE);
 
-        if ((naddr_ != 0) && (login_ip_set_ == 0 || char_ip_set_ == 0)) { 
+        if ((naddr_ != 0) && (login_ip_set_ == 0 || char_ip_set_ == 0)) {
           // The char server should know what IP address it is running on
           //   - MouseJstr
           int localaddr = ntohl(addr_[0]);
           unsigned char *ptr = (unsigned char *) &localaddr;
           char buf[16];
           sprintf(buf, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]);;
-          if (naddr_ != 1) 
+          if (naddr_ != 1)
             printf("Multiple interfaces detected..  using %s as our IP address\n", buf);
           else
             printf("Defaulting to %s as our IP address\n", buf);
@@ -3393,9 +3395,9 @@ int do_init(int argc, char **argv) {
           if (char_ip_set_ == 0)
           	strcpy(char_ip_str, buf);
 
-          if (ptr[0] == 192 && ptr[1] == 168)  
+          if (ptr[0] == 192 && ptr[1] == 168)
             printf("Firewall detected.. edit lan_support.conf and char_athena.conf\n");
-        } 
+        }
 
 	login_ip = inet_addr(login_ip_str);
 	char_ip = inet_addr(char_ip_str);
@@ -3406,7 +3408,7 @@ int do_init(int argc, char **argv) {
 	}
 
 	online_players_max = 256;
-	online_chars = calloc(sizeof(struct online_chars) * 256, 1);
+	online_chars = (struct online_chars*)aCalloc(sizeof(struct online_chars) * 256, 1);
 	if (!online_chars) {
 		printf("out of memory: do_init (calloc).\n");
 		exit(1);
@@ -3432,7 +3434,7 @@ int do_init(int argc, char **argv) {
 	add_timer_func_list(check_connect_login_server, "check_connect_login_server");
 	add_timer_func_list(send_users_tologin, "send_users_tologin");
 	add_timer_func_list(mmo_char_sync_timer, "mmo_char_sync_timer");
-	
+
 	i = add_timer_interval(gettick() + 1000, check_connect_login_server, 0, 0, 10 * 1000);
 	i = add_timer_interval(gettick() + 1000, send_users_tologin, 0, 0, 5 * 1000);
 	i = add_timer_interval(gettick() + autosave_interval, mmo_char_sync_timer, 0, 0, autosave_interval);
@@ -3446,12 +3448,12 @@ int do_init(int argc, char **argv) {
 		add_timer_interval(gettick()+10, flush_timer,0,0,flush_time);
 
 
-	
+
 	if(anti_freeze_enable > 0) {
 		add_timer_func_list(map_anti_freeze_system, "map_anti_freeze_system");
 		i = add_timer_interval(gettick() + 1000, map_anti_freeze_system, 0, 0, ANTI_FREEZE_INTERVAL * 1000); // checks every X seconds user specifies
 	}
-	
+
 	if(console) {
 	    set_defaultconsoleparse(parse_console);
 	   	start_console();

+ 3 - 3
src/char/char.h

@@ -20,9 +20,9 @@ struct mmo_map_server{
 int search_character_index(char* character_name);
 char * search_character_name(int index);
 
-int mapif_sendall(unsigned char *buf, unsigned int len);
-int mapif_sendallwos(int fd,unsigned char *buf, unsigned int len);
-int mapif_send(int fd,unsigned char *buf, unsigned int len);
+int mapif_sendall(char *buf, unsigned int len);
+int mapif_sendallwos(int fd,char *buf, unsigned int len);
+int mapif_send(int fd,char *buf, unsigned int len);
 
 int char_log(char *fmt, ...);
 

+ 12 - 12
src/char/int_guild.c

@@ -398,7 +398,7 @@ int inter_guild_init() {
 			continue;
 		}
 
-		g = calloc(sizeof(struct guild), 1);
+		g = aCalloc(sizeof(struct guild), 1);
 		if(g == NULL){
 			printf("int_guild: out of memory!\n");
 			exit(0);
@@ -412,7 +412,7 @@ int inter_guild_init() {
 			guild_calcinfo(g);
 		} else {
 			printf("int_guild: broken data [%s] line %d\n", guild_txt, c);
-			free(g);
+			aFree(g);
 		}
 		c++;
 	}
@@ -426,7 +426,7 @@ int inter_guild_init() {
 	}
 
 	while(fgets(line, sizeof(line)-1, fp)) {
-		gc = calloc(sizeof(struct guild_castle), 1);
+		gc = aCalloc(sizeof(struct guild_castle), 1);
 		if(gc == NULL){
 			printf("int_guild: out of memory!\n");
 			exit(0);
@@ -436,7 +436,7 @@ int inter_guild_init() {
 			numdb_insert(castle_db, gc->castle_id, gc);
 		} else {
 			printf("int_guild: broken data [%s] line %d\n", castle_txt, c);
-			free(gc);
+			aFree(gc);
 		}
 		c++;
 	}
@@ -445,7 +445,7 @@ int inter_guild_init() {
 		printf(" %s - making Default Data...\n", castle_txt);
 		//デフォルトデータを作成
 		for(i = 0; i < MAX_GUILDCASTLE; i++) {
-			gc = calloc(sizeof(struct guild_castle), 1);
+			gc = aCalloc(sizeof(struct guild_castle), 1);
 			if (gc == NULL) {
 				printf("int_guild: out of memory!\n");
 				exit(0);
@@ -577,7 +577,7 @@ int guild_check_empty(struct guild *g) {
 	numdb_erase(guild_db, g->guild_id);
 	inter_guild_storage_delete(g->guild_id);
 	mapif_guild_broken(g->guild_id, 0);
-	free(g);
+	aFree(g);
 
 	return 1;
 }
@@ -765,7 +765,7 @@ int mapif_guild_memberinfoshort(struct guild *g, int idx) {
 	WBUFL(buf, 2) = g->guild_id;
 	WBUFL(buf, 6) = g->member[idx].account_id;
 	WBUFL(buf,10) = g->member[idx].char_id;
-	WBUFB(buf,14) = g->member[idx].online;
+	WBUFB(buf,14) = (unsigned char)g->member[idx].online;
 	WBUFW(buf,15) = g->member[idx].lv;
 	WBUFW(buf,17) = g->member[idx].class_;
 	mapif_sendall(buf, 19);
@@ -965,7 +965,7 @@ int mapif_parse_CreateGuild(int fd, int account_id, char *name, struct guild_mem
 		mapif_guild_created(fd, account_id, NULL);
 		return 0;
 	}
-	g = calloc(sizeof(struct guild), 1);
+	g = aCalloc(sizeof(struct guild), 1);
 	if (g == NULL) {
 		printf("int_guild: CreateGuild: out of memory !\n");
 		mapif_guild_created(fd, account_id, NULL);
@@ -1085,7 +1085,7 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in
 }
 
 // オンライン/Lv更新
-int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id, int char_id, int online, int lv, int class) {
+int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id, int char_id, int online, int lv, int class_) {
 	struct guild *g;
 	int i, alv, c;
 
@@ -1101,7 +1101,7 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id,
 		if (g->member[i].account_id == account_id && g->member[i].char_id == char_id) {
 			g->member[i].online = online;
 			g->member[i].lv = lv;
-			g->member[i].class_ = class;
+			g->member[i].class_ = class_;
 			mapif_guild_memberinfoshort(g, i);
 		}
 		if (g->member[i].account_id > 0) {
@@ -1111,7 +1111,7 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id,
 		if (g->member[i].online)
 			g->connect_member++;
 	}
-	
+
 	if (c)
 		// 平均レベル
 		g->average_lv = alv / c;
@@ -1147,7 +1147,7 @@ int mapif_parse_BreakGuild(int fd, int guild_id) {
 
 	if(log_inter)
 		inter_log("guild %s (id=%d) broken" RETCODE, g->name, guild_id);
-	free(g);
+	aFree(g);
 
 	return 0;
 }

+ 4 - 4
src/char/int_party.c

@@ -94,7 +94,7 @@ int inter_party_init() {
 			continue;
 		}
 
-		p = calloc(sizeof(struct party), 1);
+		p = aCalloc(sizeof(struct party), 1);
 		if (p == NULL){
 			printf("int_party: out of memory!\n");
 			exit(0);
@@ -107,7 +107,7 @@ int inter_party_init() {
 			party_check_empty(p);
 		} else {
 			printf("int_party: broken data [%s] line %d\n", party_txt, c + 1);
-			free(p);
+			aFree(p);
 		}
 		c++;
 	}
@@ -199,7 +199,7 @@ int party_check_empty(struct party *p) {
 		// ’N‚à‚¢‚È‚¢‚̂ʼnðŽU
 	mapif_party_broken(p->party_id, 0);
 	numdb_erase(party_db, p->party_id);
-	free(p);
+	aFree(p);
 
 	return 1;
 }
@@ -391,7 +391,7 @@ int mapif_parse_CreateParty(int fd, int account_id, char *name, char *nick, char
 		mapif_party_created(fd, account_id, NULL);
 		return 0;
 	}
-	p = calloc(sizeof(struct party), 1);
+	p = aCalloc(sizeof(struct party), 1);
 	if (p == NULL) {
 		printf("int_party: out of memory !\n");
 		mapif_party_created(fd,account_id,NULL);

+ 4 - 4
src/char/int_pet.c

@@ -88,7 +88,7 @@ int inter_pet_init()
 	if( (fp=fopen(pet_txt,"r"))==NULL )
 		return 1;
 	while(fgets(line,sizeof(line),fp)){
-		p=calloc(sizeof(struct s_pet), 1);
+		p=aCalloc(sizeof(struct s_pet), 1);
 		if(p==NULL){
 			printf("int_pet: out of memory!\n");
 			exit(0);
@@ -100,7 +100,7 @@ int inter_pet_init()
 			numdb_insert(pet_db,p->pet_id,p);
 		}else{
 			printf("int_pet: broken data [%s] line %d\n",pet_txt,c);
-			free(p);
+			aFree(p);
 		}
 		c++;
 	}
@@ -210,7 +210,7 @@ int mapif_create_pet(int fd,int account_id,int char_id,short pet_class,short pet
 	short pet_equip,short intimate,short hungry,char rename_flag,char incuvate,char *pet_name)
 {
 	struct s_pet *p;
-	p=malloc(sizeof(struct s_pet));
+	p=aMalloc(sizeof(struct s_pet));
 	if(p==NULL){
 		printf("int_pet: out of memory !\n");
 		mapif_pet_created(fd,account_id,NULL);
@@ -282,7 +282,7 @@ int mapif_save_pet(int fd,int account_id,struct s_pet *data)
 		pet_id = data->pet_id;
 		p=numdb_search(pet_db,pet_id);
 		if(p == NULL) {
-			p=malloc(sizeof(struct s_pet));
+			p=aMalloc(sizeof(struct s_pet));
 			if(p==NULL){
 				printf("int_pet: out of memory !\n");
 				mapif_save_pet_ack(fd,account_id,1);

+ 8 - 8
src/char/int_storage.c

@@ -192,7 +192,7 @@ struct storage *account2storage(int account_id)
 	struct storage *s;
 	s=numdb_search(storage_db,account_id);
 	if(s == NULL) {
-		s = calloc(sizeof(struct storage), 1);
+		s = aCalloc(sizeof(struct storage), 1);
 		if(s==NULL){
 			printf("int_storage: out of memory!\n");
 			exit(0);
@@ -210,7 +210,7 @@ struct guild_storage *guild2storage(int guild_id)
 	if(inter_guild_search(guild_id) != NULL) {
 		gs=numdb_search(guild_storage_db,guild_id);
 		if(gs == NULL) {
-			gs = calloc(sizeof(struct guild_storage), 1);
+			gs = aCalloc(sizeof(struct guild_storage), 1);
 			if(gs==NULL){
 				printf("int_storage: out of memory!\n");
 				exit(0);
@@ -242,7 +242,7 @@ int inter_storage_init()
 	}
 	while(fgets(line,65535,fp)){
 		sscanf(line,"%d",&tmp_int);
-		s=calloc(sizeof(struct storage), 1);
+		s=aCalloc(sizeof(struct storage), 1);
 		if(s==NULL){
 			printf("int_storage: out of memory!\n");
 			exit(0);
@@ -254,7 +254,7 @@ int inter_storage_init()
 		}
 		else{
 			printf("int_storage: broken data [%s] line %d\n",storage_txt,c);
-			free(s);
+			aFree(s);
 		}
 		c++;
 	}
@@ -270,7 +270,7 @@ int inter_storage_init()
 	}
 	while(fgets(line,65535,fp)){
 		sscanf(line,"%d",&tmp_int);
-		gs=calloc(sizeof(struct guild_storage), 1);
+		gs=aCalloc(sizeof(struct guild_storage), 1);
 		if(gs==NULL){
 			printf("int_storage: out of memory!\n");
 			exit(0);
@@ -282,7 +282,7 @@ int inter_storage_init()
 		}
 		else{
 			printf("int_storage: broken data [%s] line %d\n",guild_storage_txt,c);
-			free(gs);
+			aFree(gs);
 		}
 		c++;
 	}
@@ -356,7 +356,7 @@ int inter_storage_delete(int account_id)
 				inter_pet_delete(*((long *)(&s->storage[i].card[2])));
 		}
 		numdb_erase(storage_db,account_id);
-		free(s);
+		aFree(s);
 	}
 	return 0;
 }
@@ -372,7 +372,7 @@ int inter_guild_storage_delete(int guild_id)
 				inter_pet_delete(*((long *)(&gs->storage[i].card[2])));
 		}
 		numdb_erase(guild_storage_db,guild_id);
-		free(gs);
+		aFree(gs);
 	}
 	return 0;
 }

+ 6 - 6
src/char/inter.c

@@ -114,7 +114,7 @@ int inter_accreg_init() {
 	while(fgets(line, sizeof(line)-1, fp)){
 		line[sizeof(line)-1] = '\0';
 
-		reg = calloc(sizeof(struct accreg), 1);
+		reg = aCalloc(sizeof(struct accreg), 1);
 		if (reg == NULL) {
 			printf("inter: accreg: out of memory!\n");
 			exit(0);
@@ -123,7 +123,7 @@ int inter_accreg_init() {
 			numdb_insert(accreg_db, reg->account_id, reg);
 		} else {
 			printf("inter: accreg: broken data [%s] line %d\n", accreg_txt, c);
-			free(reg);
+			aFree(reg);
 		}
 		c++;
 	}
@@ -371,7 +371,7 @@ int check_ttl_wisdata() {
 			// removed. not send information after a timeout. Just no answer for the player
 			//mapif_wis_end(wd, 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
 			numdb_erase(wis_db, wd->id);
-			free(wd);
+			aFree(wd);
 		}
 	} while(wis_delnum >= WISDELLIST_MAX);
 
@@ -423,7 +423,7 @@ int mapif_parse_WisRequest(int fd) {
 			mapif_send(fd, buf, 27);
 		} else {
 
-			wd = (struct WisData *)calloc(sizeof(struct WisData), 1);
+			wd = (struct WisData *)aCalloc(sizeof(struct WisData), 1);
 			if (wd == NULL){
 				printf("inter: WisRequest: out of memory !\n");
 				return 0;
@@ -458,7 +458,7 @@ int mapif_parse_WisReply(int fd) {
 	if ((--wd->count) <= 0 || flag != 1) {
 		mapif_wis_end(wd, flag); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
 		numdb_erase(wis_db, id);
-		free(wd);
+		aFree(wd);
 	}
 
 	return 0;
@@ -481,7 +481,7 @@ int mapif_parse_AccReg(int fd) {
 	struct accreg *reg = numdb_search(accreg_db, RFIFOL(fd,4));
 
 	if (reg == NULL) {
-		if ((reg = calloc(sizeof(struct accreg), 1)) == NULL) {
+		if ((reg = aCalloc(sizeof(struct accreg), 1)) == NULL) {
 			printf("inter: accreg: out of memory !\n");
 			exit(0);
 		}

+ 48 - 48
src/char_sql/char.c

@@ -73,7 +73,7 @@ char login_db_level[32] = "level";
 
 int lowest_gm_level = 1;
 
-unsigned char *SQL_CONF_NAME = "conf/inter_athena.conf";
+char *SQL_CONF_NAME = "conf/inter_athena.conf";
 
 struct mmo_map_server server[MAX_MAP_SERVERS];
 int server_fd[MAX_MAP_SERVERS];
@@ -206,9 +206,9 @@ void set_char_offline(int char_id, int account_id) {
     if ( char_id == 99 )
         sprintf(tmp_sql,"UPDATE `%s` SET `online`='0' WHERE `account_id`='%d'", char_db, account_id);
     else {
-        cp = numdb_search(char_db_,char_id);
+        cp = (struct mmo_charstatus*)numdb_search(char_db_,char_id);
         if (cp != NULL) {
-            free(cp);
+            aFree(cp);
             numdb_erase(char_db_,char_id);
         }
 
@@ -229,7 +229,7 @@ void set_char_offline(int char_id, int account_id) {
 //-----------------------------------------------------
 // Function to suppress control characters in a string.
 //-----------------------------------------------------
-int remove_control_chars(unsigned char *str) {
+int remove_control_chars(char *str) {
 	int i;
 	int change = 0;
 
@@ -259,7 +259,7 @@ int isGM(int account_id) {
 
 void read_gm_account(void) {
 	if (gm_account != NULL)
-		free(gm_account);
+		aFree(gm_account);
 	GM_num = 0;
 
 	sprintf(tmp_lsql, "SELECT `%s`,`%s` FROM `%s` WHERE `%s`>='%d'",login_db_account_id,login_db_level,login_db,login_db_level,lowest_gm_level);
@@ -268,7 +268,7 @@ void read_gm_account(void) {
 	}
 	lsql_res = mysql_store_result(&lmysql_handle);
 	if (lsql_res) {
-		gm_account = aCalloc(sizeof(struct gm_account) * mysql_num_rows(lsql_res), 1);
+		gm_account = (struct gm_account*)aCalloc(sizeof(struct gm_account) * mysql_num_rows(lsql_res), 1);
 		while ((lsql_row = mysql_fetch_row(lsql_res))) {
 			gm_account[GM_num].account_id = atoi(lsql_row[0]);
 			gm_account[GM_num].level = atoi(lsql_row[1]);
@@ -329,7 +329,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 
 	if (char_id!=p->char_id) return 0;
 
-	cp = numdb_search(char_db_,char_id);
+	cp = (struct mmo_charstatus*)numdb_search(char_db_,char_id);
 
 	if (cp == NULL) {
 		cp = (struct mmo_charstatus *) aMalloc(sizeof(struct mmo_charstatus));
@@ -441,7 +441,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 
 //=====================================================================================================
 
-	if ((p->base_exp != cp->base_exp) || (p->class_ != cp->class_) || 
+	if ((p->base_exp != cp->base_exp) || (p->class_ != cp->class_) ||
 	    (p->base_level != cp->base_level) || (p->job_level != cp->job_level) ||
 	    (p->job_exp != cp->job_exp) || (p->zeny != cp->zeny) ||
 	    (p->last_point.x != cp->last_point.x) || (p->last_point.y != cp->last_point.y) ||
@@ -457,7 +457,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 	    (p->shield != cp->shield) || (p->head_top != cp->head_top) ||
 	    (p->head_mid != cp->head_mid) || (p->head_bottom != cp->head_bottom) ||
 	    (p->partner_id != cp->partner_id)) {
-	
+
 //}//---------------------------test count------------------------------
 	//check party_exist
 	party_exist=0;
@@ -546,7 +546,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 
 	diff = 0;
 	for(i=0;i<MAX_SKILL;i++) {
-            if ((p->skill[i].lv != 0) && (p->skill[i].id == 0)) 
+            if ((p->skill[i].lv != 0) && (p->skill[i].id == 0))
                 p->skill[i].id = i; // Fix skill tree
 
             if((p->skill[i].id != cp->skill[i].id) || (p->skill[i].lv != cp->skill[i].lv) ||
@@ -589,7 +589,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 	    break;
 	  }
 	}
-	
+
 	if (diff) {
 	//printf("- Save global_reg_value data to MySQL!\n");
 	//`global_reg_value` (`char_id`, `str`, `value`)
@@ -603,7 +603,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 		if (p->global_reg[i].str) {
 			if(p->global_reg[i].value !=0){
 					sprintf(tmp_sql,"INSERT INTO `%s` (`char_id`, `str`, `value`) VALUES ('%d', '%s','%d')",
-					         reg_db, char_id, jstrescapecpy(temp_str,(unsigned char*)p->global_reg[i].str), p->global_reg[i].value);
+					         reg_db, char_id, jstrescapecpy(temp_str,p->global_reg[i].str), p->global_reg[i].value);
 					if(mysql_query(&mysql_handle, tmp_sql)) {
 						printf("DB server Error (insert `global_reg_value`)- %s\n", mysql_error(&mysql_handle));
 					}
@@ -612,9 +612,9 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 	}
 	}
 
-	// Friends list 
+	// Friends list
 	// account_id, friend_id0, name0, ...
-	
+
 	tmp_p += sprintf(tmp_p, "REPLACE INTO `%s` (`id`, `account_id`",friend_db);
 
 	diff = 0;
@@ -623,7 +623,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 		tmp_p += sprintf(tmp_p, ", `friend_id%d`, `name%d`", i, i);
 
 	tmp_p += sprintf(tmp_p, ") VALUES (NULL, '%d'", char_id);
-	
+
 	for (i=0;i<20;i++) {
 		tmp_p += sprintf(tmp_p, ", '%d', '%s'", p->friend_id[i], p->friend_name[i]);
 		if ((p->friend_id[i] != cp->friend_id[i]) ||
@@ -633,7 +633,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 
 	tmp_p += sprintf(tmp_p, ")");
 
-	if (diff) 
+	if (diff)
 	  mysql_query(&mysql_handle, tmp_sql);
 
 	printf("saving char is done.\n");
@@ -882,9 +882,9 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p, int online){
 	char *tmp_p = tmp_sql;
 	struct mmo_charstatus *cp;
 
-	cp = numdb_search(char_db_,char_id);
+	cp = (struct mmo_charstatus*)numdb_search(char_db_,char_id);
 	if (cp != NULL)
-	  free(cp);
+	  aFree(cp);
 
 	memset(p, 0, sizeof(struct mmo_charstatus));
 
@@ -966,10 +966,10 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p, int online){
 	} else
 		printf("char2 - failed\n");	//Error?! ERRRRRR WHAT THAT SAY!?
 
-	if (p->last_point.x == 0 || p->last_point.y == 0 || p->last_point.map[0] == '\0') 
+	if (p->last_point.x == 0 || p->last_point.y == 0 || p->last_point.map[0] == '\0')
 		memcpy(&p->last_point, &start_point, sizeof(start_point));
 
-	if (p->save_point.x == 0 || p->save_point.y == 0 || p->save_point.map[0] == '\0') 
+	if (p->save_point.x == 0 || p->save_point.y == 0 || p->save_point.map[0] == '\0')
 		memcpy(&p->save_point, &start_point, sizeof(start_point));
 
 	printf("char2 ");
@@ -1102,10 +1102,10 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p, int online){
 	sql_row = mysql_fetch_row(sql_res);
 
 	i=mysql_num_rows(sql_res);
-	
+
 	// debugg
 	//printf("mysql: %d\n",i);
-	
+
 	// Create an entry for the character if it doesnt already have one
 	if(!i) {
 
@@ -1188,15 +1188,15 @@ int mmo_char_sql_init(void) {
 		printf("set char_id_count: %d.......\n",char_id_count);
 
 	sprintf(tmp_sql , "REPLACE INTO `%s` SET `online`=0", char_db);
-	if (mysql_query(&mysql_handle, tmp_sql)) 
+	if (mysql_query(&mysql_handle, tmp_sql))
 		printf("DB server Error - %s\n", mysql_error(&mysql_handle));
 
 	sprintf(tmp_sql , "REPLACE INTO `%s` SET `online`=0", guild_member_db);
-	if (mysql_query(&mysql_handle, tmp_sql)) 
+	if (mysql_query(&mysql_handle, tmp_sql))
 		printf("DB server Error - %s\n", mysql_error(&mysql_handle));
 
 	sprintf(tmp_sql , "REPLACE INTO `%s` SET `connect_member`=0", guild_db);
-	if (mysql_query(&mysql_handle, tmp_sql)) 
+	if (mysql_query(&mysql_handle, tmp_sql))
 		printf("DB server Error - %s\n", mysql_error(&mysql_handle));
 
 	printf("init end.......\n");
@@ -1212,10 +1212,10 @@ int make_new_char_sql(int fd, unsigned char *dat) {
 	int i;
 
 	//aphostropy error check! - fixed!
-	jstrescapecpy(t_name, dat);
+	jstrescapecpy(t_name, (char*)dat);
 	printf("making new char -");
 
-	sd = session[fd]->session_data;
+	sd = (struct char_session_data*)session[fd]->session_data;
 
 	// Check Authorised letters/symbols in the name of the character
 	if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorised
@@ -1477,7 +1477,7 @@ int parse_tologin(int fd) {
 		return 0;
 	}
 
-	sd = session[fd]->session_data;
+	sd = (struct char_session_data*)session[fd]->session_data;
 
 	// hehe. no need to set user limite on SQL version. :P
 	// but char limitation is good way to maintain server. :D
@@ -1513,7 +1513,7 @@ int parse_tologin(int fd) {
 			if(RFIFOREST(fd)<51)
 				return 0;
 			for(i = 0; i < fd_max; i++) {
-				if (session[i] && (sd = session[i]->session_data) && sd->account_id == RFIFOL(fd,2)) {
+				if (session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->account_id == RFIFOL(fd,2)) {
 					if (RFIFOB(fd,6) != 0) {
 						WFIFOW(i,0) = 0x6c;
 						WFIFOB(i,2) = 0x42;
@@ -1546,7 +1546,7 @@ int parse_tologin(int fd) {
 			if (RFIFOREST(fd) < 50)
 				return 0;
 			for(i = 0; i < fd_max; i++) {
-				if (session[i] && (sd = session[i]->session_data)) {
+				if (session[i] && (sd = (struct char_session_data*)session[i]->session_data)) {
 					if (sd->account_id == RFIFOL(fd,2)) {
 					sd->connect_until_time = (time_t)RFIFOL(fd,46);
 					break;
@@ -1606,22 +1606,22 @@ int parse_tologin(int fd) {
 				sql_res = mysql_store_result(&mysql_handle);
 
 				if (sql_res) {
-						int char_id, jobclass, skill_point, class;
+						int char_id, jobclass, skill_point, class_;
 						sql_row = mysql_fetch_row(sql_res);
 						char_id = atoi(sql_row[0]);
 						jobclass = atoi(sql_row[1]);
 						skill_point = atoi(sql_row[2]);
-						class = jobclass;
+						class_ = jobclass;
 						if (jobclass == 19 || jobclass == 20 ||
 						    jobclass == 4020 || jobclass == 4021 ||
 						    jobclass == 4042 || jobclass == 4043) {
 							// job modification
 							if (jobclass == 19 || jobclass == 20) {
-								class = (sex) ? 19 : 20;
+								class_ = (sex) ? 19 : 20;
 							} else if (jobclass == 4020 || jobclass == 4021) {
-								class = (sex) ? 4020 : 4021;
+								class_ = (sex) ? 4020 : 4021;
 							} else if (jobclass == 4042 || jobclass == 4043) {
-								class = (sex) ? 4042 : 4043;
+								class_ = (sex) ? 4042 : 4043;
 							}
 							// remove specifical skills of classes 19,20 4020,4021 and 4042,4043
 							sprintf(tmp_sql, "SELECT `lv` FROM `%s` WHERE `char_id` = '%d' AND `id` >= '315' AND `id` <= '330'",skill_db, char_id);
@@ -1644,7 +1644,7 @@ int parse_tologin(int fd) {
 						if (mysql_query(&mysql_handle, tmp_sql)) {
 							printf("DB server Error (select `char`)- %s\n", mysql_error(&mysql_handle));
 						}
-						sprintf(tmp_sql, "UPDATE `%s` SET `class`='%d' , `skill_point`='%d' , `weapon`='0' , `shield='0' , `head_top`='0' , `head_mid`='0' , `head_bottom`='0' WHERE `char_id` = '%d'",char_db, class, skill_point, char_id);
+						sprintf(tmp_sql, "UPDATE `%s` SET `class`='%d' , `skill_point`='%d' , `weapon`='0' , `shield='0' , `head_top`='0' , `head_mid`='0' , `head_bottom`='0' WHERE `char_id` = '%d'",char_db, class_, skill_point, char_id);
 						if (mysql_query(&mysql_handle, tmp_sql)) {
 							printf("DB server Error (select `char`)- %s\n", mysql_error(&mysql_handle));
 						}
@@ -1652,7 +1652,7 @@ int parse_tologin(int fd) {
 				}
 				// disconnect player if online on char-server
 				for(i = 0; i < fd_max; i++) {
-					if (session[i] && (sd = session[i]->session_data)) {
+					if (session[i] && (sd = (struct char_session_data*)session[i]->session_data)) {
 						if (sd->account_id == acc) {
 							session[i]->eof = 1;
 							break;
@@ -1706,7 +1706,7 @@ int parse_tologin(int fd) {
 		  }
 			// disconnect player if online on char-server
 			for(i = 0; i < fd_max; i++) {
-				if (session[i] && (sd = session[i]->session_data)) {
+				if (session[i] && (sd = (struct char_session_data*)session[i]->session_data)) {
 					if (sd->account_id == RFIFOL(fd,2)) {
 						session[i]->eof = 1;
 						break;
@@ -2296,7 +2296,7 @@ int parse_char(int fd) {
 	struct char_session_data *sd;
 	unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
 
-	sd = session[fd]->session_data;
+	sd = (struct char_session_data*)session[fd]->session_data;
 
         if(login_fd < 0)
 		session[fd]->eof = 1;
@@ -2353,7 +2353,7 @@ int parse_char(int fd) {
 */
 			if (sd == NULL) {
 				CREATE(session[fd]->session_data, struct char_session_data, 1);
-				sd = session[fd]->session_data;
+				sd = (struct char_session_data*)session[fd]->session_data;
 				sd->connect_until_time = 0; // unknow or illimited (not displaying on map-server)
 			}
 			sd->account_id = RFIFOL(fd, 2);
@@ -2843,15 +2843,15 @@ int parse_console(char *buf) {
 
     printf("Type of command: %s || Command: %s \n",type,command);
 
-    if(buf) free(buf);
-    if(type) free(type);
-    if(command) free(command);
+    if(buf) aFree(buf);
+    if(type) aFree(type);
+    if(command) aFree(command);
 
     return 0;
 }
 
 // MAP send all
-int mapif_sendall(unsigned char *buf, unsigned int len) {
+int mapif_sendall(char *buf, unsigned int len) {
 	int i, c;
 	int fd;
 
@@ -2867,7 +2867,7 @@ int mapif_sendall(unsigned char *buf, unsigned int len) {
 	return c;
 }
 
-int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len) {
+int mapif_sendallwos(int sfd, char *buf, unsigned int len) {
 	int i, c;
 	int fd;
 
@@ -2883,7 +2883,7 @@ int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len) {
 	return c;
 }
 
-int mapif_send(int fd, unsigned char *buf, unsigned int len) {
+int mapif_send(int fd, char *buf, unsigned int len) {
 	int i;
 
 	if (fd >= 0) {
@@ -3016,12 +3016,12 @@ void do_final(void) {
 		printf("DB server Error (insert `char`)- %s\n", mysql_error(&mysql_handle));
 
 	if(gm_account)  {
-		free(gm_account);
+		aFree(gm_account);
 		gm_account = 0;
 	}
 
 	if(char_dat)  {
-		free(char_dat);
+		aFree(char_dat);
 		char_dat = 0;
 	}
 

+ 3 - 3
src/char_sql/char.h

@@ -41,9 +41,9 @@ struct itemtemp{
 	struct itemtmp equip[MAX_GUILD_STORAGE],notequip[MAX_GUILD_STORAGE];
 };
 int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int char_id,int tableswitch);
-int mapif_sendall(unsigned char *buf,unsigned int len);
-int mapif_sendallwos(int fd,unsigned char *buf,unsigned int len);
-int mapif_send(int fd,unsigned char *buf,unsigned int len);
+int mapif_sendall(char *buf,unsigned int len);
+int mapif_sendallwos(int fd,char *buf,unsigned int len);
+int mapif_send(int fd,char *buf,unsigned int len);
 
 extern int autosave_interval;
 extern char db_path[];

+ 98 - 98
src/char_sql/int_guild.c

@@ -46,7 +46,7 @@ static int _erase_guild(void *key, void *data, va_list ap) {
     int guild = va_arg(ap, int);
     struct guild_castle * castle = (struct guild_castle *) data;
     if (castle->guild_id == guild) {
-        free(castle);
+        aFree(castle);
         db_erase(castle_db_, key);
     }
 
@@ -60,21 +60,21 @@ int inter_guild_tosql(struct guild *g,int flag)
 	// 2 `guild_member` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`rsv1`,`rsv2`,`name`)
 	// 4 `guild_position` (`guild_id`,`position`,`name`,`mode`,`exp_mode`)
 	// 8 `guild_alliance` (`guild_id`,`opposition`,`alliance_id`,`name`)
-	// 16 `guild_expulsion` (`guild_id`,`name`,`mes`,`acc`,`account_id`,`rsv1`,`rsv2`,`rsv3`) 
+	// 16 `guild_expulsion` (`guild_id`,`name`,`mes`,`acc`,`account_id`,`rsv1`,`rsv2`,`rsv3`)
 	// 32 `guild_skill` (`guild_id`,`id`,`lv`)
-	
+
 	char t_name[100],t_master[24],t_mes1[60],t_mes2[240],t_member[24],t_position[24],t_alliance[24];  // temporay storage for str convertion;
 	char t_ename[24],t_emes[40];
 	char emblem_data[4096];
 	int i=0;
 	int guild_exist=0,guild_member=0,guild_online_member=0;
-	
+
 	if (g->guild_id<=0) return -1;
-	
+
 	printf("(\033[1;35m%d\033[0m)  Request save guild -(flag 0x%x) ",g->guild_id, flag);
-	
+
 	jstrescapecpy(t_name, g->name);
-	
+
 	//printf("- Check if guild %d exists\n",g->guild_id);
 	sprintf(tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'",guild_db,g->guild_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
@@ -87,7 +87,7 @@ int inter_guild_tosql(struct guild *g,int flag)
 		//printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes"));
 	}
 	mysql_free_result(sql_res) ; //resource free
-	
+
 	if (guild_exist >0){
 		// Check members in party
 		sprintf(tmp_sql,"SELECT count(*) FROM `%s` WHERE `guild_id`='%d'",guild_member_db, g->guild_id);
@@ -98,13 +98,13 @@ int inter_guild_tosql(struct guild *g,int flag)
 		sql_res = mysql_store_result(&mysql_handle) ;
 		if (sql_res!=NULL && mysql_num_rows(sql_res)>0) {
 			sql_row = mysql_fetch_row(sql_res);
-			
+
 			guild_member =  atoi (sql_row[0]);
 		//	printf("- Check members in guild %d : %d \n",g->guild_id,guild_member);
 
 		}
 		mysql_free_result(sql_res) ; //resource free
-		
+
 		// Delete old guild from sql
 		if (flag&1||guild_member==0){
 		//	printf("- Delete guild %d from guild\n",g->guild_id);
@@ -164,7 +164,7 @@ int inter_guild_tosql(struct guild *g,int flag)
 			sprintf(tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'",guild_castle_db, g->guild_id);
 			if(mysql_query(&mysql_handle, tmp_sql) ) {
 				printf("DB server Error (delete `guild_castle`)- %s\n", mysql_error(&mysql_handle) );
-			}			
+			}
                         db_foreach(castle_db_, _erase_guild, g->guild_id);
 		}
 	}
@@ -175,14 +175,14 @@ int inter_guild_tosql(struct guild *g,int flag)
 		if (g->member[i].account_id>0) guild_online_member++;
 		i++;
 	}
-	
+
 	// No member in guild , no need to create it in sql
 	if (guild_member <= 0 && guild_online_member <=0) {
 		inter_guild_storage_delete(g->guild_id);
 		printf("No member in guild %d , break it! \n",g->guild_id);
 		return -2;
 	}
-	
+
 	// Insert new guild to sqlserver
 	if (flag&1||guild_member==0){
 		int len=0;
@@ -190,7 +190,7 @@ int inter_guild_tosql(struct guild *g,int flag)
 		for(i=0;i<g->emblem_len;i++){
 			len+=sprintf(emblem_data+len,"%02x",(unsigned char)(g->emblem_data[i]));
 			//printf("%02x",(unsigned char)(g->emblem_data[i]));
-		}	
+		}
                 emblem_data[len] = '\0';
 		//printf("- emblem_len = %d \n",g->emblem_len);
 		sprintf(tmp_sql,"INSERT INTO `%s` "
@@ -204,7 +204,7 @@ int inter_guild_tosql(struct guild *g,int flag)
 			printf("DB server Error (insert `guild`)- %s\n", mysql_error(&mysql_handle) );
 		}
 	}
-	
+
 	if (flag&2||guild_member==0){
 	  struct StringBuf sbuf;
 	  struct StringBuf sbuf2;
@@ -238,16 +238,16 @@ int inter_guild_tosql(struct guild *g,int flag)
 	  }
 	  StringBuf_Printf(&sbuf2,")");
 
-	  if(mysql_query(&mysql_handle, StringBuf_Value(&sbuf))) 
+	  if(mysql_query(&mysql_handle, StringBuf_Value(&sbuf)))
 	    printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
 
-	  if(mysql_query(&mysql_handle, StringBuf_Value(&sbuf2))) 
+	  if(mysql_query(&mysql_handle, StringBuf_Value(&sbuf2)))
 	    printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
 
 	  StringBuf_Destroy(&sbuf2);
 	  StringBuf_Destroy(&sbuf);
 	}
-	
+
 	if (flag&4||guild_member==0){
 		//printf("- Insert guild %d to guild_position\n",g->guild_id);
 		for(i=0;i<MAX_GUILDPOSITION;i++){
@@ -279,7 +279,7 @@ int inter_guild_tosql(struct guild *g,int flag)
 				//printf(" %s\n",tmp_sql);
 				if(mysql_query(&mysql_handle, tmp_sql) ) {
 					printf("DB server Error (insert `guild_alliance`)- %s\n", mysql_error(&mysql_handle) );
-				}		
+				}
 			}
 		}
 	}
@@ -314,7 +314,7 @@ int inter_guild_tosql(struct guild *g,int flag)
 			}
 		}
 	}
-	
+
 	printf("Save guild done\n");
 	return 0;
 }
@@ -332,10 +332,10 @@ struct guild * inter_guild_fromsql(int guild_id)
 	g = numdb_search(guild_db_,guild_id);
 	if (g != NULL)
 		return g;
-	
+
 	g = (struct guild *) aMalloc(sizeof(struct guild));
 	memset(g,0,sizeof(struct guild));
-	
+
 //	printf("Retrieve guild information from sql ......\n");
 //	printf("- Read guild %d from sql \n",guild_id);
 
@@ -344,19 +344,19 @@ struct guild * inter_guild_fromsql(int guild_id)
 	//printf("  %s\n",tmp_sql);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (select `guild`)- %s\n", mysql_error(&mysql_handle) );
-		free(g);
+		aFree(g);
 		return 0;
 	}
-	
+
 	sql_res = mysql_store_result(&mysql_handle) ;
 	if (sql_res!=NULL && mysql_num_rows(sql_res)>0) {
 		sql_row = mysql_fetch_row(sql_res);
 		if (sql_row==NULL) {
 			mysql_free_result(sql_res);
-			free(g);
+			aFree(g);
 			return 0;
 		}
-		
+
 		g->guild_id=atoi(sql_row[0]);
 		strncpy(g->name,sql_row[1],24);
 		strncpy(g->master,sql_row[2],24);
@@ -382,7 +382,7 @@ struct guild * inter_guild_fromsql(int guild_id)
 			if(c2>='a' && c2<='f')x2=c2-'a'+10;
 			if(c2>='A' && c2<='F')x2=c2-'A'+10;
 			g->emblem_data[i]=(x1<<4)|x2;
-		}	
+		}
 	}
 	mysql_free_result(sql_res);
 
@@ -392,7 +392,7 @@ struct guild * inter_guild_fromsql(int guild_id)
 	//printf("  %s\n",tmp_sql);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (select `guild_member`)- %s\n", mysql_error(&mysql_handle) );
-		free(g);
+		aFree(g);
 		return 0;
 	}
 	sql_res = mysql_store_result(&mysql_handle) ;
@@ -415,33 +415,33 @@ struct guild * inter_guild_fromsql(int guild_id)
 		}
 	}
 	mysql_free_result(sql_res);
-	
+
 	//printf("- Read guild_position %d from sql \n",guild_id);
 	sprintf(tmp_sql,"SELECT `guild_id`,`position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'",guild_position_db, guild_id);
 	//printf("  %s\n",tmp_sql);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (select `guild_position`)- %s\n", mysql_error(&mysql_handle) );
-		free(g);
+		aFree(g);
 		return 0;
 	}
 	sql_res = mysql_store_result(&mysql_handle) ;
 	if (sql_res!=NULL && mysql_num_rows(sql_res)>0) {
 		int i;
 		for(i=0;((sql_row = mysql_fetch_row(sql_res))&&i<MAX_GUILDPOSITION);i++){
-			int position = atoi(sql_row[1]);	
+			int position = atoi(sql_row[1]);
 			struct guild_position *p = &g->position[position];
-			strncpy(p->name,sql_row[2],24);	
+			strncpy(p->name,sql_row[2],24);
 			p->mode=atoi(sql_row[3]);
-			p->exp_mode=atoi(sql_row[4]);	
+			p->exp_mode=atoi(sql_row[4]);
 		}
 	}
-	mysql_free_result(sql_res);	
+	mysql_free_result(sql_res);
 
 	//printf("- Read guild_alliance %d from sql \n",guild_id);
 	sprintf(tmp_sql,"SELECT `guild_id`,`opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'",guild_alliance_db, guild_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (select `guild_alliance`)- %s\n", mysql_error(&mysql_handle) );
-		free(g);
+		aFree(g);
 		return 0;
 	}
 	sql_res = mysql_store_result(&mysql_handle) ;
@@ -455,12 +455,12 @@ struct guild * inter_guild_fromsql(int guild_id)
 		}
 	}
 	mysql_free_result(sql_res);
-	
+
 	//printf("- Read guild_expulsion %d from sql \n",guild_id);
 	sprintf(tmp_sql,"SELECT `guild_id`,`name`,`mes`,`acc`,`account_id`,`rsv1`,`rsv2`,`rsv3` FROM `%s` WHERE `guild_id`='%d'",guild_expulsion_db, guild_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (select `guild_expulsion`)- %s\n", mysql_error(&mysql_handle) );
-		free(g);
+		aFree(g);
 		return 0;
 	}
 	sql_res = mysql_store_result(&mysql_handle) ;
@@ -476,16 +476,16 @@ struct guild * inter_guild_fromsql(int guild_id)
 			e->rsv1=atoi(sql_row[5]);
 			e->rsv2=atoi(sql_row[6]);
 			e->rsv3=atoi(sql_row[7]);
-			
+
 		}
 	}
 	mysql_free_result(sql_res);
-	
+
 	//printf("- Read guild_skill %d from sql \n",guild_id);
 	sprintf(tmp_sql,"SELECT `guild_id`,`id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`",guild_skill_db, guild_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (select `guild_skill`)- %s\n", mysql_error(&mysql_handle) );
-		free(g);
+		aFree(g);
 		return 0;
 	}
 	sql_res = mysql_store_result(&mysql_handle) ;
@@ -497,7 +497,7 @@ struct guild * inter_guild_fromsql(int guild_id)
 		}
 	}
 	mysql_free_result(sql_res);
-							
+
 //	printf("Successfully retrieve guild information from sql!\n");
 
 	numdb_insert(guild_db_, guild_id,g);
@@ -542,8 +542,8 @@ int inter_guildcastle_tosql(struct guild_castle *gc)
 		"(`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`,"
 		"`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`,"
 		"`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7`)"
-		"VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')", 
-		guild_castle_db, gc->castle_id, gc->guild_id,  gc->economy, gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime, 
+		"VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')",
+		guild_castle_db, gc->castle_id, gc->guild_id,  gc->economy, gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime,
 		gc->createTime, gc->visibleC, gc->visibleG0, gc->visibleG1, gc->visibleG2, gc->visibleG3, gc->visibleG4, gc->visibleG5,
 		gc->visibleG6, gc->visibleG7, gc->Ghp0, gc->Ghp1, gc->Ghp2, gc->Ghp3, gc->Ghp4, gc->Ghp5, gc->Ghp6, gc->Ghp7);
 	//printf(" %s\n",tmp_sql);
@@ -558,7 +558,7 @@ int inter_guildcastle_tosql(struct guild_castle *gc)
 		printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
 		return 0;
 	}
-		
+
 	sprintf(tmp_sql,"UPDATE `%s` SET `castle_id`='%d' WHERE `guild_id`='%d'",guild_db, gc->castle_id,gc->guild_id);
 	//printf(" %s\n",tmp_sql);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
@@ -567,7 +567,7 @@ int inter_guildcastle_tosql(struct guild_castle *gc)
 	}
 
         db_foreach(guild_db_, _set_guild_castle, gc->castle_id,gc->guild_id);
-	
+
 	return 0;
 }
 // Read guild_castle from sql
@@ -603,7 +603,7 @@ int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc)
 			mysql_free_result(sql_res);
 			return 0;
 		}
-		
+
 		gc->guild_id =  atoi (sql_row[1]);
 		gc->economy = atoi (sql_row[2]);
 		gc->defense = atoi (sql_row[3]);
@@ -629,7 +629,7 @@ int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc)
 		gc->Ghp5 = atoi (sql_row[23]);
 		gc->Ghp6 = atoi (sql_row[24]);
 		gc->Ghp7 = atoi (sql_row[25]);
-		
+
 		//printf("Read Castle %d of guild %d from sql \n",castle_id,gc->guild_id);
 
 	}
@@ -647,7 +647,7 @@ int inter_guild_readdb()
 	FILE *fp;
 	char line[1024];
 	for (i=0;i<100;i++) guild_exp[i]=0;
-	
+
 	fp=fopen("db/exp_guild.txt","r");
 	if(fp==NULL){
 		printf("can't read db/exp_guild.txt\n");
@@ -676,14 +676,14 @@ int inter_guild_sql_init()
         guild_expcache_db_=numdb_init();
         guild_infoevent_db_=numdb_init();
         guild_castleinfoevent_db_=numdb_init();
-	
+
 	printf("interserver guild memory initialize.... (%d byte)\n",sizeof(struct guild));
 	guild_pt = aCalloc(sizeof(struct guild), 1);
 	guild_pt2= aCalloc(sizeof(struct guild), 1);
 	guildcastle_pt=aCalloc(sizeof(struct guild_castle), 1);
-	
+
 	inter_guild_readdb(); // Read exp
-	
+
 	sprintf (tmp_sql , "SELECT count(*) FROM `%s`",guild_db);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
@@ -702,13 +702,13 @@ int inter_guild_sql_init()
 			printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
 			exit(0);
 		}
-		
+
 		sql_res = mysql_store_result(&mysql_handle) ;
 		sql_row = mysql_fetch_row(sql_res);
 		guild_newid = atoi(sql_row[0])+1;
 		mysql_free_result(sql_res);
 	}
-	
+
 	printf("set guild_newid: %d.......\n",guild_newid);
 
 	return 0;
@@ -743,7 +743,7 @@ int guild_check_empty(struct guild *g)
 			return 0;
 		}
 	}
-	
+
 	// 誰もいないので解散
 	mapif_guild_broken(g->guild_id,0);
 	inter_guild_storage_delete(g->guild_id);
@@ -795,7 +795,7 @@ int guild_calcinfo(struct guild *g)
 			nextexp = guild_nextexp(g->guild_lv);
 		}
 	}
-	
+
 	// ギルドの次の経験値
 	g->next_exp = guild_nextexp(g->guild_lv);
 
@@ -809,13 +809,13 @@ int guild_calcinfo(struct guild *g)
 		if(g->member[i].account_id>0){
 			g->average_lv+=g->member[i].lv;
 			c++;
-			
+
 			if(g->member[i].online>0)
 				g->connect_member++;
 		}
 	}
 	if(c) g->average_lv/=c;
-	
+
 	// 全データを送る必要がありそう
 	if(	g->max_member!=before.max_member	||
 		g->guild_lv!=before.guild_lv		||
@@ -823,7 +823,7 @@ int guild_calcinfo(struct guild *g)
 		mapif_guild_info(-1,g);
 		return 1;
 	}
-		
+
 	return 0;
 }
 
@@ -906,7 +906,7 @@ int mapif_guild_memberinfoshort(struct guild *g,int idx)
 	WBUFL(buf, 2)=g->guild_id;
 	WBUFL(buf, 6)=g->member[idx].account_id;
 	WBUFL(buf,10)=g->member[idx].char_id;
-	WBUFB(buf,14)=g->member[idx].online;
+	WBUFB(buf,14)=(unsigned char)g->member[idx].online;
 	WBUFW(buf,15)=g->member[idx].lv;
 	WBUFW(buf,17)=g->member[idx].class_;
 	mapif_sendall(buf,19);
@@ -1121,7 +1121,7 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
 {
 	struct guild *g;
 	int i;
-	
+
 	printf("CreateGuild\n");
 	g=search_guildname(name);
 	if(g!=NULL&&g->guild_id>0){
@@ -1135,38 +1135,38 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
 	memcpy(g->name,name,24);
 	memcpy(g->master,master->name,24);
 	memcpy(&g->member[0],master,sizeof(struct guild_member));
-	
+
 	g->position[0].mode=0x11;
 	strcpy(g->position[                  0].name,"GuildMaster");
 	strcpy(g->position[MAX_GUILDPOSITION-1].name,"Newbie");
 	for(i=1;i<MAX_GUILDPOSITION-1;i++)
 		sprintf(g->position[i].name,"Position %d",i+1);
-	
+
 	// Initialize guild property
 	g->max_member=16;
 	g->average_lv=master->lv;
 	g->castle_id=-1;
 	for(i=0;i<MAX_GUILDSKILL;i++)
 		g->skill[i].id=i + GD_SKILLBASE;
-	
+
 	// Save to sql
 	printf("Create initialize OK!\n");
 	i=inter_guild_tosql(g,255);
-	
+
 	if (i<0) {
 		mapif_guild_created(fd,account_id,NULL);
 		return 0;
 	}
-	
+
 	// Report to client
 	mapif_guild_created(fd,account_id,g);
 	mapif_guild_info(fd,g);
-	
+
 	if(log_inter)
 		inter_log("guild %s (id=%d) created by master %s (id=%d)" RETCODE,
 			name, g->guild_id, master->name, master->account_id );
-	
-	
+
+
 	return 0;
 }
 // Return guild info to client
@@ -1191,10 +1191,10 @@ int mapif_parse_GuildAddMember(int fd,int guild_id,struct guild_member *m)
 		mapif_guild_memberadded(fd,guild_id,m->account_id,m->char_id,1);
 		return 0;
 	}
-	
+
 	for(i=0;i<g->max_member;i++){
 		if(g->member[i].account_id==0){
-			
+
 			memcpy(&g->member[i],m,sizeof(struct guild_member));
 			mapif_guild_memberadded(fd,guild_id,m->account_id,m->char_id,0);
 			guild_calcinfo(g);
@@ -1211,7 +1211,7 @@ int mapif_parse_GuildAddMember(int fd,int guild_id,struct guild_member *m)
 int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int flag,const char *mes)
 {
 	struct guild *g= inter_guild_fromsql(guild_id);
-	
+
 	if(g!=NULL&&g->guild_id>0){
 		int i;
 		for(i=0;i<g->max_member;i++){
@@ -1219,7 +1219,7 @@ int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int fl
 				g->member[i].char_id==char_id){
 				printf("%d %d\n",i, (int)(&g->member[i]));
 				printf("%d %s\n",i, g->member[i].name);
-				
+
 				if(flag){	// 追放の場合追放リストに入れる
 					int j;
 					for(j=0;j<MAX_GUILDEXPLUSION;j++){
@@ -1236,12 +1236,12 @@ int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int fl
 					memcpy(g->explusion[j].name,g->member[i].name,24);
 					memcpy(g->explusion[j].mes,mes,40);
 				}
-				
+
 				mapif_guild_leaved(guild_id,account_id,char_id,flag,g->member[i].name,mes);
 				printf("%d %d\n",i, (int)(&g->member[i]));
 				printf("%d %s\n",i, (&g->member[i])->name);
 				memset(&g->member[i],0,sizeof(struct guild_member));
-				
+
 				if( guild_check_empty(g)==0 )
 					mapif_guild_info(-1,g);// まだ人がいるのでデータ送信
 				/*
@@ -1259,12 +1259,12 @@ int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int fl
 		}
 		/* mapif_guild_leaved(guild_id,account_id,char_id,flag,g->member[i].name,mes);	*/
 	}
-	
+
 	return 0;
 }
 // Change member info
 int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
-	int account_id,int char_id,int online,int lv,int class)
+	int account_id,int char_id,int online,int lv,int class_)
 {
 	// Could speed up by manipulating only guild_member
 	struct guild * g= inter_guild_fromsql(guild_id);
@@ -1272,18 +1272,18 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
 
 	if(g==NULL||g->guild_id<=0)
 		return 0;
-	
+
 	g->connect_member=0;
 
 	idx = -1;
-	
+
 	for(i=0,alv=0,c=0;i<g->max_member;i++){
 		if(	g->member[i].account_id==account_id &&
 			g->member[i].char_id==char_id){
-			
+
 			g->member[i].online=online;
 			g->member[i].lv=lv;
-			g->member[i].class_=class;
+			g->member[i].class_=class_;
 			mapif_guild_memberinfoshort(g,i);
 			idx = i;
 		}
@@ -1300,13 +1300,13 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
 		g->average_lv=alv/c;
 
 	sprintf(tmp_sql, "UPDATE `%s` SET `connect_member`=%d,`average_lv`=%d WHERE `guild_id`='%d'", guild_db,  g->connect_member, g->average_lv,  g->guild_id);
-	if(mysql_query(&mysql_handle, tmp_sql) ) 
+	if(mysql_query(&mysql_handle, tmp_sql) )
 	  printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
 
 	sprintf(tmp_sql, "UPDATE `%s` SET `online`=%d,`lv`=%d,`class`=%d WHERE `char_id`=%d", guild_member_db, g->member[idx].online, g->member[idx].lv, g->member[idx].class_, g->member[idx].char_id);
-	if(mysql_query(&mysql_handle, tmp_sql) ) 
+	if(mysql_query(&mysql_handle, tmp_sql) )
 	  printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
-	
+
 	return 0;
 }
 
@@ -1316,7 +1316,7 @@ int mapif_parse_BreakGuild(int fd,int guild_id)
 	struct guild *g= inter_guild_fromsql(guild_id);
 	if(g==NULL)
 		return 0;
-	
+
 	// Delete guild from sql
 	//printf("- Delete guild %d from guild\n",guild_id);
 	sprintf(tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'",guild_db, guild_id);
@@ -1348,7 +1348,7 @@ int mapif_parse_BreakGuild(int fd,int guild_id)
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (delete `guild_position`)- %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//printf("- Delete guild %d from guild_castle\n",guild_id);
 	sprintf(tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'",guild_castle_db, guild_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
@@ -1356,19 +1356,19 @@ int mapif_parse_BreakGuild(int fd,int guild_id)
 	}
 
         db_foreach(castle_db_, _erase_guild, guild_id);
-	
+
 	//printf("- Update guild %d of char\n",guild_id);
 	sprintf(tmp_sql, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'",char_db, guild_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error (delete `guild_position`)- %s\n", mysql_error(&mysql_handle) );
 	}
-		
+
 	inter_guild_storage_delete(guild_id);
 	mapif_guild_broken(guild_id,0);
-	
+
 	if(log_inter)
 		inter_log("guild %s (id=%d) broken" RETCODE,g->name,guild_id);
-	
+
 	return 0;
 }
 
@@ -1416,7 +1416,7 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int cha
 	struct guild * g = inter_guild_fromsql(guild_id);
 
 	//printf("GuildMemberInfoChange %s \n",(type==GMI_EXP)?"GMI_EXP":"OTHER");
-	
+
 	if(g==NULL){
 		return 0;
 	}
@@ -1437,7 +1437,7 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int cha
 	    inter_guild_tosql(g,3); // Change guild & guild_member
 	    break;
 	  }
-	case GMI_EXP:	
+	case GMI_EXP:
 	  {	// EXP
 	    int exp,oldexp=g->member[i].exp;
 	    exp=g->member[i].exp=*((unsigned int *)data);
@@ -1447,11 +1447,11 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int cha
 	    mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len);
 
 	    sprintf(tmp_sql, "UPDATE `%s` SET `guild_lv`=%d,`connect_member`=%d,`max_member`=%d,`average_lv`=%d,`exp`=%d,`next_exp`=%d,`skill_point`=%d WHERE `guild_id`='%d'", guild_db, g->guild_lv, g->connect_member, g->max_member, g->average_lv, g->exp, g->next_exp, g->skill_point, g->guild_id);
-	    if(mysql_query(&mysql_handle, tmp_sql) ) 
+	    if(mysql_query(&mysql_handle, tmp_sql) )
 	      printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
 
 	    sprintf(tmp_sql, "UPDATE `%s` SET `exp`=%d  WHERE `char_id`=%d", guild_member_db, g->member[i].exp, g->member[i].char_id);
-	    if(mysql_query(&mysql_handle, tmp_sql) ) 
+	    if(mysql_query(&mysql_handle, tmp_sql) )
 	      printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
 	    break;
 	  }
@@ -1488,7 +1488,7 @@ int mapif_parse_GuildSkillUp(int fd,int guild_id,int skill_num,int account_id)
 	if(g == NULL || idx < 0 || idx >= MAX_GUILDSKILL)
 		return 0;
 	//printf("GuildSkillUp\n");
-	
+
 	if(	g->skill_point>0 && g->skill[idx].id>0 &&
 		g->skill[idx].lv<10 ){
 		g->skill[idx].lv++;
@@ -1511,10 +1511,10 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,
 	int j,i;
 	g[0]= inter_guild_fromsql(guild_id1);
 	g[1]= inter_guild_fromsql(guild_id2);
-	
+
 	if(g[0]==NULL || g[1]==NULL || g[0]->guild_id ==0 || g[1]->guild_id==0)
 		return 0;
-		
+
 	if(!(flag&0x8)){
 		for(i=0;i<2-(flag&1);i++){
 			for(j=0;j<MAX_GUILDALLIANCE;j++)
@@ -1545,7 +1545,7 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,
 int mapif_parse_GuildNotice(int fd,int guild_id,const char *mes1,const char *mes2)
 {
 	struct guild *g= inter_guild_fromsql(guild_id);
-	
+
 	if(g==NULL||g->guild_id<=0)
 		return 0;
 	memcpy(g->mes1,mes1,60);
@@ -1557,7 +1557,7 @@ int mapif_parse_GuildNotice(int fd,int guild_id,const char *mes1,const char *mes
 int mapif_parse_GuildEmblem(int fd,int len,int guild_id,int dummy,const char *data)
 {
 	struct guild * g= inter_guild_fromsql(guild_id);
-	
+
 	if(g==NULL||g->guild_id<=0)
 		return 0;
 	memcpy(g->emblem_data,data,len);

+ 1 - 1
src/char_sql/int_party.c

@@ -207,7 +207,7 @@ int inter_party_sql_init(){
 	
 	//memory alloc
 	printf("interserver party memory initialize.... (%d byte)\n",sizeof(struct party));
-	party_pt = calloc(sizeof(struct party), 1);
+	party_pt = aCalloc(sizeof(struct party), 1);
 	
 	sprintf (tmp_sql , "SELECT count(*) FROM `%s`",party_db);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {

+ 1 - 1
src/char_sql/int_pet.c

@@ -105,7 +105,7 @@ int inter_pet_sql_init(){
 		
 	//memory alloc
 	printf("interserver pet memory initialize.... (%d byte)\n",sizeof(struct s_pet));
-	pet_pt = calloc(sizeof(struct s_pet), 1);
+	pet_pt = aCalloc(sizeof(struct s_pet), 1);
 
 	sprintf (tmp_sql , "SELECT count(*) FROM `%s`", pet_db);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {

+ 2 - 2
src/char_sql/int_storage.c

@@ -191,8 +191,8 @@ int inter_storage_sql_init(){
 	
 	//memory alloc
 	printf("interserver storage memory initialize....(%d byte)\n",sizeof(struct storage));
-	storage_pt=calloc(sizeof(struct storage), 1);
-	guild_storage_pt=calloc(sizeof(struct guild_storage), 1);
+	storage_pt=aCalloc(sizeof(struct storage), 1);
+	guild_storage_pt=aCalloc(sizeof(struct guild_storage), 1);
 	memset(storage_pt,0,sizeof(struct storage));
 	memset(guild_storage_pt,0,sizeof(struct guild_storage));
 	

+ 2 - 2
src/char_sql/inter.c

@@ -402,7 +402,7 @@ int check_ttl_wisdata() {
 			// removed. not send information after a timeout. Just no answer for the player
 			//mapif_wis_end(wd, 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
 			numdb_erase(wis_db, wd->id);
-			free(wd);
+			aFree(wd);
 		}
 	} while(wis_delnum >= WISDELLIST_MAX);
 
@@ -490,7 +490,7 @@ int mapif_parse_WisReply(int fd) {
 	if ((--wd->count) <= 0 || flag != 1) {
 		mapif_wis_end(wd, flag); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
 		numdb_erase(wis_db, id);
-		free(wd);
+		aFree(wd);
 	}
 
 	return 0;

+ 4 - 4
src/char_sql/itemdb.c

@@ -172,7 +172,7 @@ static int itemdb_read_sqldb(void) // sql item_db read, shortened version of map
 
 			// Insert a new row into the item database
 /*
-			id = calloc(sizeof(struct item_data), 1);
+			id = aCalloc(sizeof(struct item_data), 1);
 
 			if (id == NULL) {
 				printf("out of memory : itemdb_read_sqldb\n");
@@ -214,10 +214,10 @@ static int itemdb_final(void *key,void *data,va_list ap)
 
 	id=data;
 	if(id->use_script)
-		free(id->use_script);
+		aFree(id->use_script);
 	if(id->equip_script)
-		free(id->equip_script);
-	free(id);
+		aFree(id->equip_script);
+	aFree(id);
 
 	return 0;
 }

+ 1 - 1
src/char_sql/itemdb.h

@@ -6,7 +6,7 @@ struct item_data {
 	char name[24],jname[24];
 	int value_buy,value_sell,value_notdc,value_notoc;
 	int type;
-	int class;
+	int class_;
 	int sex;
 	int equip;
 	int weight;

+ 1 - 0
src/common/core.c

@@ -9,6 +9,7 @@
 #include <signal.h>
 #include <string.h>
 
+#include "../common/mmo.h"
 #include "core.h"
 #include "socket.h"
 #include "timer.h"

+ 3 - 3
src/common/db.c

@@ -424,7 +424,7 @@ void* db_erase(struct dbt *table,void* key)
 #ifdef MALLOC_DBN
 	free_dbn(p);
 #else
-	free(p);
+	aFree(p);
 #endif
 	return data;
 }
@@ -497,11 +497,11 @@ void db_final(struct dbt *table,int (*func)(void*,void*,va_list),...)
 #ifdef MALLOC_DBN
 			free_dbn(p);
 #else
-			free(p);
+			aFree(p);
 #endif
 			p=pn;
 		}
 	}
-	free(table);
+	aFree(table);
 	va_end(ap);
 }

+ 33 - 35
src/common/grfio.c

@@ -25,8 +25,6 @@
 #include <ctype.h>
 #include <sys/stat.h>
 
-#include <zlib.h>
-
 #include "utils.h"
 #include "grfio.h"
 #include "mmo.h"
@@ -284,7 +282,7 @@ static void decode_des_etc(BYTE *buf,int len,int type,int cycle)
  *	Grf data decode sub : zip
  *------------------------------------------
  */
-int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen)
+int decode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen)
 {
 	z_stream stream;
 	int err;
@@ -301,21 +299,21 @@ int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
 	stream.zalloc = (alloc_func)0;
 	stream.zfree = (free_func)0;
 
-	err = inflateInit(&stream);
+	err = zlib_inflateInit(&stream);
 	if (err != Z_OK) return err;
 
-	err = inflate(&stream, Z_FINISH);
+	err = zlib_inflate(&stream, Z_FINISH);
 	if (err != Z_STREAM_END) {
-		inflateEnd(&stream);
+		zlib_inflateEnd(&stream);
 		return err == Z_OK ? Z_BUF_ERROR : err;
 	}
 	*destLen = stream.total_out;
 
-	err = inflateEnd(&stream);
+	err = zlib_inflateEnd(&stream);
 	return err;
 }
 
-int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) {
+int encode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen) {
 	z_stream stream;
 	int err;
 
@@ -513,14 +511,14 @@ int grfio_size(char *fname)
 		char lfname[256],*rname,*p;
 		FILELIST lentry;
 		struct stat st;
-		
+
 	    if(strcmp(data_dir, "") != 0 && (rname=grfio_resnametable(fname,lfname))!=NULL) {
             //printf("%s\t",fname);
             //sprintf(rname,"%s",grfio_resnametable(fname,lfname));
             //printf("%s\n",rname);
             sprintf(lfname,"%s%s",data_dir,rname);
             //printf("%s\n",lfname);
-        }    
+        }
 
 		for(p=&lfname[0];*p!=0;p++) if (*p=='\\') *p = '/';	// * At the time of Unix
 
@@ -557,7 +555,7 @@ void* grfio_reads(char *fname, int *size)
 
 		strncpy(lfname,fname,255);
 		// i hope this is the correct way =p [celest]
-		if ((rname=grfio_resnametable(fname,lfname))!=NULL) {			
+		if ((rname=grfio_resnametable(fname,lfname))!=NULL) {
 			char tbuf[255];
 			//sprintf(rname,"%s",grfio_resnametable(fname,lfname));
 			sprintf(tbuf,"%s%s",data_dir,rname);
@@ -576,7 +574,7 @@ void* grfio_reads(char *fname, int *size)
 				lentry.declen = ftell(in);
 			}
 			fseek(in,0,0);	// SEEK_SET
-			buf2 = (unsigned char *) aCalloc(lentry.declen+1024, 1);
+			buf2 = (unsigned char *) aCallocA(lentry.declen+1024, 1);
 			if (buf2==NULL) {
 				printf("file read memory allocate error : declen\n");
 				goto errret;
@@ -592,13 +590,13 @@ void* grfio_reads(char *fname, int *size)
 			} else {
 				printf("%s not found (grfio_reads)\n", fname);
 				//goto errret;
-				free(buf2);
+				aFree(buf2);
 				return NULL;
 			}
 		}
 	}
 	if (entry!=NULL && entry->gentry>0) {	// Archive[GRF] File Read
-		buf = (unsigned char *) aCalloc(entry->srclen_aligned+1024, 1);
+		buf = (unsigned char *) aCallocA(entry->srclen_aligned+1024, 1);
 		if (buf==NULL) {
 			printf("file read memory allocate error : srclen_aligned\n");
 			goto errret;
@@ -608,13 +606,13 @@ void* grfio_reads(char *fname, int *size)
 		if(in==NULL) {
 			printf("%s not found (grfio_reads)\n",gfname);
 			//goto errret;
-			free(buf);
+			aFree(buf);
 			return NULL;
 		}
 		fseek(in,entry->srcpos,0);
 		fread(buf,1,entry->srclen_aligned,in);
 		fclose(in);
-		buf2 = (unsigned char *) aCalloc(entry->declen+1024, 1);
+		buf2 = (unsigned char *) aCallocA(entry->declen+1024, 1);
 		if (buf2==NULL) {
 			printf("file decode memory allocate error\n");
 			goto errret;
@@ -633,14 +631,14 @@ void* grfio_reads(char *fname, int *size)
 		} else {
 			memcpy(buf2,buf,entry->declen);
 		}
-		free(buf);
+		aFree(buf);
 	}
 	if (size!=NULL && entry!=NULL)
 		*size = entry->declen;
 	return buf2;
 errret:
-	if (buf!=NULL) free(buf);
-	if (buf2!=NULL) free(buf2);
+	if (buf!=NULL) aFree(buf);
+	if (buf2!=NULL) aFree(buf2);
 	if (in!=NULL) fclose(in);
 	return NULL;
 }
@@ -704,7 +702,7 @@ static int grfio_entryread(char *gfname,int gentry)
 
 	if (grf_version==0x01) {	//****** Grf version 01xx ******
 		list_size = grf_size-ftell(fp);
-		grf_filelist = (unsigned char *) aCalloc(list_size, 1);
+		grf_filelist = (unsigned char *) aCallocA(list_size, 1);
 		if(grf_filelist==NULL){
 			fclose(fp);
 			printf("out of memory : grf_filelist\n");
@@ -727,7 +725,7 @@ static int grfio_entryread(char *gfname,int gentry)
 				fname = decode_filename(grf_filelist+ofs+6,grf_filelist[ofs]-6);
 				if(strlen((const char *) fname)>sizeof(aentry.fn)-1){
 					printf("file name too long : %s\n",fname);
-					free(grf_filelist);
+					aFree(grf_filelist);
 					exit(1);
 				}
 				srclen=0;
@@ -762,7 +760,7 @@ static int grfio_entryread(char *gfname,int gentry)
 			}
 			ofs = ofs2 + 17;
 		}
-		free(grf_filelist);
+		aFree(grf_filelist);
 
 	} else if (grf_version==0x02) {	//****** Grf version 02xx ******
 		unsigned char eheader[8];
@@ -779,15 +777,15 @@ static int grfio_entryread(char *gfname,int gentry)
 			return 4;
 		}
 
-		rBuf = (unsigned char *) aCalloc( rSize , 1);	// Get a Read Size
+		rBuf = (unsigned char *) aCallocA( rSize , 1);	// Get a Read Size
 		if (rBuf==NULL) {
 			fclose(fp);
 			printf("out of memory : grf compress entry table buffer\n");
 			return 3;
 		}
-		grf_filelist = (unsigned char *) aCalloc( eSize , 1);	// Get a Extend Size
+		grf_filelist = (unsigned char *) aCallocA( eSize , 1);	// Get a Extend Size
 		if (grf_filelist==NULL) {
-			free(rBuf);
+			aFree(rBuf);
 			fclose(fp);
 			printf("out of memory : grf extract entry table buffer\n");
 			return 3;
@@ -796,7 +794,7 @@ static int grfio_entryread(char *gfname,int gentry)
 		fclose(fp);
 		decode_zip(grf_filelist,&eSize,rBuf,rSize);	// Decode function
 		list_size = eSize;
-		free(rBuf);
+		aFree(rBuf);
 
 		entrys = getlong(grf_header+0x26) - 7;
 
@@ -808,7 +806,7 @@ static int grfio_entryread(char *gfname,int gentry)
 			fname = grf_filelist+ofs;
 			if (strlen((const char *) fname)>sizeof(aentry.fn)-1) {
 				printf("grf : file name too long : %s\n",fname);
-				free(grf_filelist);
+				aFree(grf_filelist);
 				exit(1);
 			}
 			ofs2 = ofs+strlen(grf_filelist+ofs)+1;
@@ -839,7 +837,7 @@ static int grfio_entryread(char *gfname,int gentry)
 			}
 			ofs = ofs2 + 17;
 		}
-		free(grf_filelist);
+		aFree(grf_filelist);
 
 	} else {	//****** Grf Other version ******
 		fclose(fp);
@@ -859,11 +857,11 @@ static int grfio_entryread(char *gfname,int gentry)
 static void grfio_resourcecheck()
 {
 	int size;
-	unsigned char *buf,*ptr;
+	char *buf,*ptr;
 	char w1[256],w2[256],src[256],dst[256];
 	FILELIST *entry;
 
-	buf=grfio_reads("data\\resnametable.txt",&size);
+	buf = (char*)grfio_reads("data\\resnametable.txt",&size);
 	buf[size] = 0;
 
 	for(ptr=buf;ptr-buf<size;) {
@@ -889,7 +887,7 @@ static void grfio_resourcecheck()
 		if (!ptr) break;
 		ptr++;
 	}
-	free(buf);
+	aFree(buf);
 	filelist_adjust();	// Unnecessary area release of filelist
 }
 
@@ -927,7 +925,7 @@ int grfio_add(char *fname)
 		}
 	}
 	len = strlen( fname );
-	buf = aCalloc(len+1, 1);
+	buf = (char*)aCallocA(len+1, 1);
 	if (buf==NULL) {
 		printf("out of memory : gentry\n");
 		exit(1);
@@ -953,17 +951,17 @@ void grfio_final(void)
 {
 	int lop;
 
-	if (filelist!=NULL)	free(filelist);
+	if (filelist!=NULL)	aFree(filelist);
 	filelist = NULL;
 	filelist_entrys = filelist_maxentry = 0;
 
 	if (gentry_table!=NULL) {
 		for(lop=0;lop<gentry_entrys;lop++) {
 			if (gentry_table[lop]!=NULL) {
-				free(gentry_table[lop]);
+				aFree(gentry_table[lop]);
 			}
 		}
-		free(gentry_table);
+		aFree(gentry_table);
 	}
 	gentry_table = NULL;
 	gentry_entrys = gentry_maxentry = 0;

+ 2 - 2
src/common/grfio.h

@@ -8,8 +8,8 @@ void* grfio_read(char*);		// GRFIO data file read
 void* grfio_reads(char*,int*);	// GRFIO data file read & size get
 int grfio_size(char*);			// GRFIO data file size get
 
-int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen);
-int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen);
+int decode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen);
+int encode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen);
 
 // Accessor to GRF filenames
 char *grfio_setdatafile(const char *str);

+ 21 - 2
src/common/malloc.c

@@ -1,9 +1,10 @@
-#if !defined(DMALLOC) && !defined(GCOLLECT) && !defined(BCHECK)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "malloc.h"
 
+#if !defined(DMALLOC) && !defined(GCOLLECT) && !defined(BCHECK)
+
 void* aMalloc_( size_t size, const char *file, int line, const char *func )
 {
 	void *ret;
@@ -45,9 +46,27 @@ void* aRealloc_( void *p, size_t size, const char *file, int line, const char *f
 	return ret;
 }
 
+#endif
+
+
+#if defined(GCOLLECT)
+
+void * _bcallocA(size_t size, size_t cnt) {
+	void *ret = aMallocA(size * cnt);
+	memset(ret, 0, size * cnt);
+	return ret;
+}
+
 void * _bcalloc(size_t size, size_t cnt) {
-	void *ret = malloc(size * cnt);
+	void *ret = aMalloc(size * cnt);
 	memset(ret, 0, size * cnt);
 	return ret;
 }
 #endif
+
+char * _bstrdup(const char *chr) {
+	int len = strlen(chr);
+	char *ret = aMalloc(len + 1);
+	strcpy(ret, chr);
+	return ret;
+}

+ 20 - 0
src/common/malloc.h

@@ -9,23 +9,39 @@
 
 #define aMalloc(size) \
   dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 0)
+#define aMallocA(size) \
+  dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 0)
+#define aCallocA(count,size) \
+  dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 0)
 #define aCalloc(count,size) \
   dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 0)
 #define aRealloc(ptr,size) \
   dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_REALLOC, 0)
+#define aFree(ptr) free(ptr)
+#define aStrdup(ptr) strdup(ptr)
 
 #elif defined(GCOLLECT)
 #include "gc.h"
 #define aMalloc(n) GC_MALLOC(n)
+#define aMallocA(n) GC_MALLOC_ATOMIC(n)
+#define aCallocA(m,n) _bcallocA(m,n)
 #define aCalloc(m,n) _bcalloc(m,n)
 #define aRealloc(p,n) GC_REALLOC(p,n)
+#define aFree(n) GC_FREE(n)
+#define aStrdup(n) _bstrdup(n)
 
 extern void * _bcalloc(size_t, size_t);
+extern void * _bcallocA(size_t, size_t);
+extern char * _bstrdup(const char *);
 
 #elif defined(BCHECK)
 #define aMalloc(n) malloc(n)
+#define aMallocA(n) malloc(n)
 #define aCalloc(m,n) calloc(m,n)
+#define aCallocA(m,n) calloc(m,n)
 #define aRealloc(p,n) realloc(p,n)
+#define aFree(n) free(n)
+#define aStrdup(n) strdup(n)
 #else
 
 #if __STDC_VERSION__ < 199901L
@@ -43,8 +59,12 @@ void* aCalloc_( size_t num, size_t size, const char *file, int line, const char
 void* aRealloc_( void *p, size_t size, const char *file, int line, const char *func );
 
 #define aMalloc(n) aMalloc_(n,ALC_MARK)
+#define aMallocA(n) aMalloc_(n,ALC_MARK)
 #define aCalloc(m,n) aCalloc_(m,n,ALC_MARK)
+#define aCallocA(m,n) aCalloc_(m,n,ALC_MARK)
 #define aRealloc(p,n) aRealloc_(p,n,ALC_MARK)
+#define aFree(ptr) free(ptr)
+#define aStrdup(ptr) strdup(ptr)
 
 #endif
 

+ 19 - 13
src/common/mmo.h

@@ -326,19 +326,25 @@ enum {
 	GD_DEVELOPMENT=10014,
 };
 
-#ifndef _WIN32
-#ifndef strcmpi
-#define strcmpi strcasecmp
-#endif
-#ifndef stricmp
-#define stricmp strcasecmp
-#endif
-#ifndef strncmpi
-#define strncmpi strncasecmp
-#endif
-#ifndef strnicmp
-#define strnicmp strncasecmp
-#endif
+#ifndef __WIN32
+	#ifndef strcmpi
+		#define strcmpi strcasecmp
+	#endif
+	#ifndef stricmp
+		#define stricmp strcasecmp
+	#endif
+	#ifndef strncmpi
+		#define strncmpi strncasecmp
+	#endif
+	#ifndef strnicmp
+		#define strnicmp strncasecmp
+	#endif
+#else
+	#define snprintf _snprintf
+	#define vsnprintf _vsnprintf
+	#ifndef strncmpi
+		#define strncmpi strnicmp
+	#endif
 #endif
 
 #endif	// _MMO_H_

+ 3 - 2
src/common/showmsg.c

@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "showmsg.h"
+#include "malloc.h"
 
 char tmp_output[1024] = {"\0"};
 
@@ -47,7 +48,7 @@ int _ShowMessage(const char *string, enum msg_type flag){ // by MC Cameri
 			return 1;
 	}
 	if (!(flag == MSG_DEBUG && !SHOW_DEBUG_MSG)) {
-		output = (char*)malloc(sizeof(char)*(strlen(prefix)+strlen(string)+2)); // prefix+string+two chars(space and \0)
+		output = (char*)aMalloc(sizeof(char)*(strlen(prefix)+strlen(string)+2)); // prefix+string+two chars(space and \0)
 		if (output == NULL) {
 			return 1;
 //			exit(1); // Kill server? Deadly
@@ -58,7 +59,7 @@ int _ShowMessage(const char *string, enum msg_type flag){ // by MC Cameri
 		strcat(output,string);
 		printf(output);
 		fflush(stdout);
-		free(output);
+		aFree(output);
 	}
 /*
 	if ((core_config.debug_output_level > -1) && (flag >= core_config.debug_output_level)) {

+ 34 - 30
src/common/socket.c

@@ -3,11 +3,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
+#include <errno.h>
 
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <winsock2.h>
+#include <io.h>
 #else
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -16,7 +18,6 @@
 #include <sys/time.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
-#include <errno.h>
 
 #ifndef SIOCGIFCONF
 #include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori]
@@ -151,11 +152,11 @@ static int send_from_fifo(int fd)
 	return 0;
 }
 
-void flush_fifos() 
+void flush_fifos()
 {
 	int i;
 	for(i=0;i<fd_max;i++)
-		if(session[i] != NULL && 
+		if(session[i] != NULL &&
 		   session[i]->func_send == send_from_fifo)
 			send_from_fifo(i);
 }
@@ -177,20 +178,22 @@ static int connect_client(int listen_fd)
 	int fd;
 	struct sockaddr_in client_address;
 	int len;
+#ifndef _WIN32
 	int result;
+#endif
 
 	//printf("connect_client : %d\n",listen_fd);
 
 	len=sizeof(client_address);
 
-	fd=accept(listen_fd,(struct sockaddr*)&client_address,&len);
+	fd = accept(listen_fd,(struct sockaddr*)&client_address,(socklen_t*)&len);
 	if(fd_max<=fd) fd_max=fd+1;
 
 	setsocketopts(fd);
 
 	if(fd==-1)
 		perror("accept");
-	else 
+	else
 		FD_SET(fd,&readfds);
 
 #ifdef _WIN32
@@ -203,8 +206,8 @@ static int connect_client(int listen_fd)
 #endif
 
 	CREATE(session[fd], struct socket_data, 1);
-	CREATE(session[fd]->rdata, unsigned char, rfifo_size);
-	CREATE(session[fd]->wdata, unsigned char, wfifo_size);
+	CREATE_A(session[fd]->rdata, unsigned char, rfifo_size);
+	CREATE_A(session[fd]->wdata, unsigned char, wfifo_size);
 
 	session[fd]->max_rdata   = rfifo_size;
 	session[fd]->max_wdata   = wfifo_size;
@@ -240,7 +243,7 @@ int make_listen_port(int port)
 
 	server_address.sin_family      = AF_INET;
 	server_address.sin_addr.s_addr = htonl( INADDR_ANY );
-	server_address.sin_port        = htons(port);
+	server_address.sin_port        = htons((unsigned short)port);
 
 	result = bind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
 	if( result == -1 ) {
@@ -271,12 +274,13 @@ int make_listen_port(int port)
 int console_recieve(int i) {
 	int n;
 	char *buf;
-	
-	CREATE(buf, char , 64);
-	
+
+	CREATE_A(buf, char , 64);
+
 	memset(buf,0,sizeof(64));
 
 	n = read(0, buf , 64);
+
 	if ( n < 0 )
 		printf("Console input read error\n");
 	else
@@ -298,21 +302,21 @@ static int null_console_parse(char *buf)
 // Console Input [Wizputer]
 int start_console(void) {
 	FD_SET(0,&readfds);
-    
+
 	CREATE(session[0], struct socket_data, 1);
 	if(session[0]==NULL){
 		printf("out of memory : start_console\n");
 		exit(1);
 	}
-	
+
 	memset(session[0],0,sizeof(*session[0]));
-	
+
 	session[0]->func_recv = console_recieve;
 	session[0]->func_console = default_console_parse;
-	
+
 	return 0;
-}   
-    
+}
+
 int make_connection(long ip,int port)
 {
 	struct sockaddr_in server_address;
@@ -320,14 +324,14 @@ int make_connection(long ip,int port)
 	int result;
 
 	fd = socket( AF_INET, SOCK_STREAM, 0 );
-	if(fd_max<=fd) 
+	if(fd_max<=fd)
 		fd_max=fd+1;
 
 	setsocketopts(fd);
 
 	server_address.sin_family = AF_INET;
 	server_address.sin_addr.s_addr = ip;
-	server_address.sin_port = htons(port);
+	server_address.sin_port = htons((unsigned short)port);
 
 #ifdef _WIN32
         {
@@ -343,8 +347,8 @@ int make_connection(long ip,int port)
 	FD_SET(fd,&readfds);
 
 	CREATE(session[fd], struct socket_data, 1);
-	CREATE(session[fd]->rdata, unsigned char, rfifo_size);
-	CREATE(session[fd]->wdata, unsigned char, wfifo_size);
+	CREATE_A(session[fd]->rdata, unsigned char, rfifo_size);
+	CREATE_A(session[fd]->wdata, unsigned char, wfifo_size);
 
 	session[fd]->max_rdata  = rfifo_size;
 	session[fd]->max_wdata  = wfifo_size;
@@ -363,12 +367,12 @@ int delete_session(int fd)
 	FD_CLR(fd,&readfds);
 	if(session[fd]){
 		if(session[fd]->rdata)
-			free(session[fd]->rdata);
+			aFree(session[fd]->rdata);
 		if(session[fd]->wdata)
-			free(session[fd]->wdata);
+			aFree(session[fd]->wdata);
 		if(session[fd]->session_data)
-			free(session[fd]->session_data);
-		free(session[fd]);
+			aFree(session[fd]->session_data);
+		aFree(session[fd]);
 	}
 	session[fd]=NULL;
 	//printf("delete_session:%d\n",fd);
@@ -401,7 +405,7 @@ int WFIFOSET(int fd,int len)
 	}
 	s->wdata_size=(s->wdata_size+(len)+2048 < s->max_wdata) ?
 		 s->wdata_size+len : (printf("socket: %d wdata lost !!\n",fd),s->wdata_size);
-	if (s->wdata_size > (TCP_FRAME_LEN)) 
+	if (s->wdata_size > (TCP_FRAME_LEN))
 		send_from_fifo(fd);
 	return 0;
 }
@@ -456,7 +460,7 @@ int do_parsepacket(void)
 	for(i=0;i<fd_max;i++){
 		if(!session[i])
 			continue;
-		if ((session[i]->rdata_tick != 0) && ((tick_ - session[i]->rdata_tick) > stall_time_)) 
+		if ((session[i]->rdata_tick != 0) && ((tick_ - session[i]->rdata_tick) > stall_time_))
 			session[i]->eof = 1;
 		if(session[i]->rdata_size==0 && session[i]->eof==0)
 			continue;
@@ -500,7 +504,7 @@ int  Net_Init(void)
     unsigned int i;
     char fullhost[255];
     struct hostent* hent;
-    
+
         /* Start up the windows networking */
     WSADATA wsaData;
 
@@ -512,7 +516,7 @@ int  Net_Init(void)
     if(gethostname(fullhost, sizeof(fullhost)) == SOCKET_ERROR) {
         printf("Ugg.. no hostname defined!\n");
         return 0;
-    } 
+    }
 
     // XXX This should look up the local IP addresses in the registry
     // instead of calling gethostbyname. However, the way IP addresses
@@ -545,7 +549,7 @@ int  Net_Init(void)
     return 0;
   }
 
-  for(pos = 0; pos < ic.ifc_len;) 
+  for(pos = 0; pos < ic.ifc_len;)
   {
     struct ifreq * ir = (struct ifreq *) (ic.ifc_buf + pos);
 

+ 2 - 1
src/common/socket.h

@@ -5,8 +5,9 @@
 
 #include <stdio.h>
 
-#ifdef _WIN32
+#ifdef __WIN32
 #include <winsock.h>
+#define close(fd) closesocket(fd)
 #else
 #include <sys/types.h>
 #include <sys/socket.h>

+ 11 - 11
src/common/strlib.c

@@ -8,15 +8,15 @@
 
 //-----------------------------------------------
 // string lib.
-unsigned char* jstrescape (unsigned char* pt) {
+char* jstrescape (char* pt) {
 	//copy from here
 	unsigned char * ptr;
 	int i =0, j=0;
-	
+
 	//copy string to temporary
-	CREATE(ptr, char, J_MAX_MALLOC_SIZE);
+	CREATE_A(ptr, char, J_MAX_MALLOC_SIZE);
 	strcpy (ptr,pt);
-	
+
 	while (ptr[i] != '\0') {
 		switch (ptr[i]) {
 			case '\'':
@@ -32,14 +32,14 @@ unsigned char* jstrescape (unsigned char* pt) {
 		}
 	}
 	pt[j++] = '\0';
-	free (ptr);
-	return (unsigned char*) &pt[0];
+	aFree (ptr);
+	return &pt[0];
 }
 
-unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt) {
+char* jstrescapecpy (char* pt,char* spt) {
 	//copy from here
 	int i =0, j=0;
-	
+
 	while (spt[i] != '\0') {
 		switch (spt[i]) {
 			case '\'':
@@ -55,12 +55,12 @@ unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt) {
 		}
 	}
 	pt[j++] = '\0';
-	return (unsigned char*) &pt[0];
+	return &pt[0];
 }
-int jmemescapecpy (unsigned char* pt,unsigned char* spt, int size) {
+int jmemescapecpy (char* pt,char* spt, int size) {
 	//copy from here
 	int i =0, j=0;
-	
+
 	while (i < size) {
 		switch (spt[i]) {
 			case '\'':

+ 3 - 3
src/common/strlib.h

@@ -4,7 +4,7 @@
 // String function library.
 // code by Jioh L. Jung (ziozzang@4wish.net)
 // This code is under license "BSD"
-unsigned char* jstrescape (unsigned char* pt);
-unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt);
-int jmemescapecpy (unsigned char* pt,unsigned char* spt, int size);
+char* jstrescape (char* pt);
+char* jstrescapecpy (char* pt,char* spt);
+int jmemescapecpy (char* pt,char* spt, int size);
 #endif

+ 5 - 5
src/common/timer.c

@@ -262,7 +262,7 @@ int add_timer(unsigned int tick,int (*func)(int,unsigned int,int,int),int id,int
 		int j;
 		if (timer_data_max == 0) {
 			timer_data_max = 256;
-			CREATE(timer_data, struct TimerData, timer_data_max);
+			CREATE_A(timer_data, struct TimerData, timer_data_max);
 			//timer_data[0] = NULL;
 		} else {
 			timer_data_max += 256;
@@ -403,13 +403,13 @@ void timer_final(void)
 	for(tfl = tfl_root; tfl; tfl = tfl_next)
 	{
 		tfl_next = tfl->next;
-		free(tfl);
+		aFree(tfl);
 		tfl = NULL;
 	}
 	if(timer_heap)
-		free(timer_heap);
+		aFree(timer_heap);
 	if(free_timer_list)
-		free(free_timer_list);
+		aFree(free_timer_list);
 	if(timer_data)
-		free(timer_data);
+		aFree(timer_data);
 }

+ 5 - 4
src/common/utils.c

@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include "malloc.h"
+#include "mmo.h"
 
 void dump(unsigned char *buffer, int num)
 {
@@ -112,7 +113,7 @@ void str_lower(char *name)
 // Allocate a StringBuf  [MouseJstr]
 struct StringBuf * StringBuf_Malloc() 
 {
-	struct StringBuf * ret = (struct StringBuf *) malloc(sizeof(struct StringBuf));
+	struct StringBuf * ret = (struct StringBuf *) aMallocA(sizeof(struct StringBuf));
 	StringBuf_Init(ret);
 	return ret;
 }
@@ -120,7 +121,7 @@ struct StringBuf * StringBuf_Malloc()
 // Initialize a previously allocated StringBuf [MouseJstr]
 void StringBuf_Init(struct StringBuf * sbuf)  {
 	sbuf->max_ = 1024;
-	sbuf->ptr_ = sbuf->buf_ = (char *) malloc(sbuf->max_ + 1);
+	sbuf->ptr_ = sbuf->buf_ = (char *) aMallocA(sbuf->max_ + 1);
 }
 
 // printf into a StringBuf, moving the pointer [MouseJstr]
@@ -169,7 +170,7 @@ int StringBuf_Append(struct StringBuf *buf1,const struct StringBuf *buf2)
 // Destroy a StringBuf [MouseJstr]
 void StringBuf_Destroy(struct StringBuf *sbuf) 
 {
-	free(sbuf->buf_);
+	aFree(sbuf->buf_);
 	sbuf->ptr_ = sbuf->buf_ = 0;
 }
 
@@ -177,7 +178,7 @@ void StringBuf_Destroy(struct StringBuf *sbuf)
 void StringBuf_Free(struct StringBuf *sbuf) 
 {
 	StringBuf_Destroy(sbuf);
-	free(sbuf);
+	aFree(sbuf);
 }
 
 // Return the built string from the StringBuf [MouseJstr]

+ 6 - 0
src/common/utils.h

@@ -30,6 +30,12 @@
    if (!((result) = (type *) aCalloc ((number), sizeof(type))))   \
       { perror("SYSERR: malloc failure"); abort(); } } while(0)
 
+#define CREATE_A(result, type, number)  do {\
+   if ((number) * sizeof(type) <= 0)   \
+      printf("SYSERR: Zero bytes or less requested at %s:%d.\n", __FILE__, __LINE__);   \
+   if (!((result) = (type *) aCallocA ((number), sizeof(type))))   \
+      { perror("SYSERR: malloc failure"); abort(); } } while(0)
+
 #define RECREATE(result,type,number) do {\
   if (!((result) = (type *) aRealloc ((result), sizeof(type) * (number))))\
       { printf("SYSERR: realloc failure"); abort(); } } while(0)

+ 5 - 5
src/ladmin/ladmin.c

@@ -280,7 +280,7 @@ int ladmin_log(char *fmt, ...) {
 			fprintf(logfp, RETCODE);
 		else {
 			gettimeofday(&tv, NULL);
-			strftime(tmpstr, 24, date_format, localtime(&(tv.tv_sec)));
+			strftime(tmpstr, 24, date_format, localtime((const time_t*)&(tv.tv_sec)));
 			sprintf(tmpstr + strlen(tmpstr), ".%03d: %s", (int)tv.tv_usec / 1000, fmt);
 			vfprintf(logfp, tmpstr, ap);
 		}
@@ -294,7 +294,7 @@ int ladmin_log(char *fmt, ...) {
 //-----------------------------------------------------
 // Function to suppress control characters in a string.
 //-----------------------------------------------------
-int remove_control_chars(unsigned char *str) {
+int remove_control_chars(char *str) {
 	int i;
 	int change = 0;
 
@@ -381,9 +381,9 @@ int verify_accountname(char* account_name) {
 //---------------------------------------------------
 // E-mail check: return 0 (not correct) or 1 (valid).
 //---------------------------------------------------
-int e_mail_check(unsigned char *email) {
+int e_mail_check(char *email) {
 	char ch;
-	unsigned char* last_arobas;
+	char* last_arobas;
 
 	// athena limits
 	if (strlen(email) < 3 || strlen(email) > 39)
@@ -3266,7 +3266,7 @@ int parse_fromlogin(int fd) {
 	}
 
 //	printf("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0));
-	sd = session[fd]->session_data;
+	sd = (struct char_session_data*)session[fd]->session_data;
 
 	while(RFIFOREST(fd) >= 2) {
 		switch(RFIFOW(fd,0)) {

+ 50 - 40
src/login/login.c

@@ -2,7 +2,7 @@
 // new version of the login-server by [Yor]
 
 #include <sys/types.h>
-#ifdef WIN32
+#ifdef __WIN32
 #define WIN32_LEAN_AND_MEAN
 #include <winsock2.h>
 #include <time.h>
@@ -232,12 +232,12 @@ void addGM(int account_id, int level) {
 			}
 			return;
 		}
-		
+
 	// if new account
 	if (i == GM_num && do_add) {
 		if (GM_num >= GM_max) {
 			GM_max += 256;
-			gm_account_db = realloc(gm_account_db, sizeof(struct gm_account) * GM_max);
+			gm_account_db = (struct gm_account*)aRealloc(gm_account_db, sizeof(struct gm_account) * GM_max);
 			memset(gm_account_db + (GM_max - 256), 0, sizeof(struct gm_account) * 256);
 		}
 		gm_account_db[GM_num].account_id = account_id;
@@ -261,7 +261,7 @@ int read_gm_account() {
 	struct stat file_stat;
 	int start_range = 0, end_range = 0, is_range = 0, current_id = 0;
 
-	if(gm_account_db) free(gm_account_db);
+	if(gm_account_db) aFree(gm_account_db);
 	GM_num = 0;
 	if(GM_max < 0)	GM_max = 256;
 	gm_account_db = (struct gm_account*)aCalloc(GM_max, sizeof(struct gm_account));
@@ -302,7 +302,7 @@ int read_gm_account() {
 					printf("read_gm_account: file [%s] invalid range, beginning of range is equal to end of range (line #%d).\n", GM_account_filename, line_counter);
 				else if (start_range>end_range)
 					printf("read_gm_account: file [%s] invalid range, beginning of range must be lower than end of range (line #%d).\n", GM_account_filename, line_counter);
-				else 
+				else
 					for (current_id = start_range;current_id<=end_range;current_id++)
 						addGM(current_id,level);
 			} else {
@@ -620,7 +620,7 @@ int mmo_auth_init(void) {
 
 			if (auth_num >= auth_max) {
 				auth_max += 256;
-				auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max);
+				auth_dat = (struct auth_dat*)aRealloc(auth_dat, sizeof(struct auth_dat) * auth_max);
 			}
 
 			memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat));
@@ -745,7 +745,7 @@ int mmo_auth_init(void) {
 
 			if (auth_num >= auth_max) {
 				auth_max += 256;
-				auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max);
+				auth_dat = (struct auth_dat*)aRealloc(auth_dat, sizeof(struct auth_dat) * auth_max);
 			}
 
 			memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat));
@@ -871,7 +871,8 @@ void mmo_auth_sync(void) {
 	FILE *fp;
 	int i, j, k, lock;
 	int account_id;
-	int id[auth_num];
+	//int id[auth_num];
+	int *id = (int *)aCalloc(auth_num, sizeof(int));
 	char line[65536];
 
 	// Sorting before save
@@ -889,8 +890,10 @@ void mmo_auth_sync(void) {
 	}
 
 	// Data save
-	if ((fp = lock_fopen(account_filename, &lock)) == NULL)
+	if ((fp = lock_fopen(account_filename, &lock)) == NULL) {
+		if (id) free(id);
 		return;
+	}
 
 	fprintf(fp, "// Accounts file: here are saved all information about the accounts.\n");
 	fprintf(fp, "// Structure: ID, account name, password, last login time, sex, # of logins, state, email, error message for state 7, validity time, last (accepted) login ip, memo field, ban timestamp, repeated(register text, register value)\n");
@@ -921,6 +924,8 @@ void mmo_auth_sync(void) {
 	if (auth_before_save_file < AUTH_BEFORE_SAVE_FILE)
 		auth_before_save_file = AUTH_BEFORE_SAVE_FILE;
 
+	if (id) aFree(id);
+
 	return;
 }
 
@@ -1019,7 +1024,7 @@ int mmo_auth_new(struct mmo_account* account, char sex, char* email) {
 
 	if (auth_num >= auth_max) {
 		auth_max += 256;
-		auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max);
+		auth_dat = (struct auth_dat*)aRealloc(auth_dat, sizeof(struct auth_dat) * auth_max);
 		memset(auth_dat, 0, sizeof(struct auth_dat) * auth_max);
 	}
 
@@ -1132,7 +1137,7 @@ int mmo_auth(struct mmo_account* account, int fd) {
 			memcpy(user_password, account->passwd, 25);
 		encpasswdok = 0;
 #ifdef PASSWORDENC
-		ld = session[fd]->session_data;
+		ld = (struct login_session_data*)session[fd]->session_data;
 		if (account->passwdenc > 0) {
 			int j = account->passwdenc;
 			if (!ld) {
@@ -1392,7 +1397,7 @@ int parse_fromchar(int fd) {
 			break;
 
 		// we receive a e-mail creation of an account with a default e-mail (no answer)
-		case 0x2715: 
+		case 0x2715:
 			if (RFIFOREST(fd) < 46)
 				return 0;
 		{
@@ -1701,7 +1706,9 @@ int parse_fromchar(int fd) {
 				acc = RFIFOL(fd,4);
 				for(i = 0; i < auth_num; i++) {
 					if (auth_dat[i].account_id == acc) {
-						unsigned char buf[RFIFOW(fd,2)+1];
+						//unsigned char buf[RFIFOW(fd,2)+1];
+						unsigned char *buf;
+						buf = (unsigned char*)aCalloc(RFIFOW(fd,2)+1, sizeof(unsigned char));
 						login_log("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s)." RETCODE,
 						          server[id].name, acc, ip);
 						for(p = 8, j = 0; p < RFIFOW(fd,2) && j < ACCOUNT_REG2_NUM; p += 36, j++) {
@@ -1718,6 +1725,7 @@ int parse_fromchar(int fd) {
 						// Save
 						mmo_auth_sync();
 //						printf("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc);
+						if (buf) free(buf);
 						break;
 					}
 				}
@@ -1883,7 +1891,8 @@ int parse_admin(int fd) {
 				return 0;
 			{
 				int st, ed, len;
-				int id[auth_num];
+				//int id[auth_num];
+				int *id=(int *)aCalloc(auth_num, sizeof(int));
 				st = RFIFOL(fd,2);
 				ed = RFIFOL(fd,6);
 				RFIFOSKIP(fd,10);
@@ -1927,6 +1936,7 @@ int parse_admin(int fd) {
 				}
 				WFIFOW(fd,2) = len;
 				WFIFOSET(fd,len);
+				if (id) free(id);
 			}
 			break;
 
@@ -2114,7 +2124,7 @@ int parse_admin(int fd) {
 					memcpy(WFIFOP(fd,4+server_num*32+6), server[i].name, 20);
 					WFIFOW(fd,4+server_num*32+26) = server[i].users;
 					WFIFOW(fd,4+server_num*32+28) = server[i].maintenance;
-					WFIFOW(fd,4+server_num*32+30) = server[i].new;
+					WFIFOW(fd,4+server_num*32+30) = server[i].new_;
 					server_num++;
 				}
 			}
@@ -2845,7 +2855,7 @@ int parse_login(int fd) {
 			} else
 				printf("parse_login: connection #%d, packet: 0x%x (with being read: %d).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
 		}
-	
+
 		switch(RFIFOW(fd,0)) {
 		case 0x200:		// New alive packet: structure: 0x200 <account.userid>.24B. used to verify if client is always alive.
 			if (RFIFOREST(fd) < 26)
@@ -2920,7 +2930,7 @@ int parse_login(int fd) {
 							memcpy(WFIFOP(fd,47+server_num*32+6), server[i].name, 20);
 							WFIFOW(fd,47+server_num*32+26) = server[i].users;
 							WFIFOW(fd,47+server_num*32+28) = server[i].maintenance;
-							WFIFOW(fd,47+server_num*32+30) = server[i].new;
+							WFIFOW(fd,47+server_num*32+30) = server[i].new_;
 							server_num++;
 						}
 					}
@@ -2984,7 +2994,7 @@ int parse_login(int fd) {
 					session[fd]->eof = 1;
 					return 0;
 				}
-				ld = session[fd]->session_data = (struct login_session_data*)aCalloc(1, sizeof(struct login_session_data));
+				ld = (struct login_session_data*)session[fd]->session_data = (struct login_session_data*)aCalloc(1, sizeof(struct login_session_data));
 				if (!ld) {
 					printf("login: Request for md5 key: memory allocation failure (malloc)!\n");
 					session[fd]->eof = 1;
@@ -3036,7 +3046,7 @@ int parse_login(int fd) {
 					memcpy(server[account.account_id].name, server_name, 20);
 					server[account.account_id].users = 0;
 					server[account.account_id].maintenance = RFIFOW(fd,82);
-					server[account.account_id].new = RFIFOW(fd,84);
+					server[account.account_id].new_ = RFIFOW(fd,84);
 					server_fd[account.account_id] = fd;
 					if(anti_freeze_enable)
 						server_freezeflag[account.account_id] = 5; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed
@@ -3105,7 +3115,7 @@ int parse_login(int fd) {
 			if (!check_ladminip(session[fd]->client_addr.sin_addr.s_addr)) {
 				login_log("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s)." RETCODE, ip);
 			} else {
-				struct login_session_data *ld = session[fd]->session_data;
+				struct login_session_data *ld = (struct login_session_data*)session[fd]->session_data;
 				if (RFIFOW(fd,2) == 0) {	// non encrypted password
 					unsigned char* password="";
 					memcpy(password, RFIFOP(fd,4), 24);
@@ -3205,9 +3215,9 @@ int parse_console(char *buf) {
 	char command[256];
 
 	memset(command,0,sizeof(command));
-    
+
 	sscanf(buf, "%[^\n]", command);
-    
+
 	login_log("Console command :%s" RETCODE, command);
 
 	if(strcmpi("shutdown", command) == 0 ||
@@ -3372,22 +3382,22 @@ int login_config_read(const char *cfgName) {
 				admin_pass[sizeof(admin_pass)-1] = '\0';
 			} else if (strcmpi(w1, "ladminallowip") == 0) {
 				if (strcmpi(w2, "clear") == 0) {
-					if (access_ladmin_allow) 
-						free(access_ladmin_allow);
+					if (access_ladmin_allow)
+						aFree(access_ladmin_allow);
 					access_ladmin_allow = NULL;
 					access_ladmin_allownum = 0;
 				} else {
 					if (strcmpi(w2, "all") == 0) {
 						// reset all previous values
 						if (access_ladmin_allow)
-							free(access_ladmin_allow);
+							aFree(access_ladmin_allow);
 						// set to all
 						access_ladmin_allow = (char*)aCalloc(ACO_STRSIZE, sizeof(char));
 						access_ladmin_allownum = 1;
 						access_ladmin_allow[0] = '\0';
 					} else if (w2[0] && !(access_ladmin_allownum == 1 && access_ladmin_allow[0] == '\0')) { // don't add IP if already 'all'
 						if (access_ladmin_allow)
-							access_ladmin_allow = realloc(access_ladmin_allow, (access_ladmin_allownum+1) * ACO_STRSIZE);
+							access_ladmin_allow = (char*)aRealloc(access_ladmin_allow, (access_ladmin_allownum+1) * ACO_STRSIZE);
 						else
 							access_ladmin_allow = (char*)aCalloc(ACO_STRSIZE, sizeof(char));
 						strncpy(access_ladmin_allow + (access_ladmin_allownum++) * ACO_STRSIZE, w2, ACO_STRSIZE);
@@ -3469,21 +3479,21 @@ int login_config_read(const char *cfgName) {
 			} else if (strcmpi(w1, "allow") == 0) {
 				if (strcmpi(w2, "clear") == 0) {
 					if (access_allow)
-						free(access_allow);
+						aFree(access_allow);
 					access_allow = NULL;
 					access_allownum = 0;
 				} else {
 					if (strcmpi(w2, "all") == 0) {
 						// reset all previous values
 						if (access_allow)
-							free(access_allow);
+							aFree(access_allow);
 						// set to all
 						access_allow = (char*)aCalloc(ACO_STRSIZE, sizeof(char));
 						access_allownum = 1;
 						access_allow[0] = '\0';
 					} else if (w2[0] && !(access_allownum == 1 && access_allow[0] == '\0')) { // don't add IP if already 'all'
 						if (access_allow)
-							access_allow = realloc(access_allow, (access_allownum+1) * ACO_STRSIZE);
+							access_allow = (char*)aRealloc(access_allow, (access_allownum+1) * ACO_STRSIZE);
 						else
 							access_allow = (char*)aCalloc(ACO_STRSIZE, sizeof(char));
 						strncpy(access_allow + (access_allownum++) * ACO_STRSIZE, w2, ACO_STRSIZE);
@@ -3493,21 +3503,21 @@ int login_config_read(const char *cfgName) {
 			} else if (strcmpi(w1, "deny") == 0) {
 				if (strcmpi(w2, "clear") == 0) {
 					if (access_deny)
-						free(access_deny);
+						aFree(access_deny);
 					access_deny = NULL;
 					access_denynum = 0;
 				} else {
 					if (strcmpi(w2, "all") == 0) {
 						// reset all previous values
 						if (access_deny)
-							free(access_deny);
+							aFree(access_deny);
 						// set to all
 						access_deny = (char*)aCalloc(ACO_STRSIZE, sizeof(char));
 						access_denynum = 1;
 						access_deny[0] = '\0';
 					} else if (w2[0] && !(access_denynum == 1 && access_deny[0] == '\0')) { // don't add IP if already 'all'
 						if (access_deny)
-							access_deny = realloc(access_deny, (access_denynum+1) * ACO_STRSIZE);
+							access_deny = (char*)aRealloc(access_deny, (access_denynum+1) * ACO_STRSIZE);
 						else
 							access_deny = (char*)aCalloc(ACO_STRSIZE, sizeof(char));
 						strncpy(access_deny + (access_denynum++) * ACO_STRSIZE, w2, ACO_STRSIZE);
@@ -3877,18 +3887,18 @@ void do_final(void) {
 	fflush(stdout);
 	mmo_auth_sync();
 
-	if(auth_dat) free(auth_dat);
-	if(gm_account_db) free(gm_account_db);
-	if(access_ladmin_allow) free(access_ladmin_allow);
-	if(access_allow) free(access_allow);
-	if(access_deny) free(access_deny);
+	if(auth_dat) aFree(auth_dat);
+	if(gm_account_db) aFree(gm_account_db);
+	if(access_ladmin_allow) aFree(access_ladmin_allow);
+	if(access_allow) aFree(access_allow);
+	if(access_deny) aFree(access_deny);
 	for (i = 0; i < MAX_SERVERS; i++) {
 		if ((fd = server_fd[i]) >= 0) {
 			server_fd[i] = -1;
 			memset(&server[i], 0, sizeof(struct mmo_char_server));
 			close(fd);
 			delete_session(fd);
-			if(session[fd]) free(session[fd]);
+			if(session[fd]) aFree(session[fd]);
 		}
 	}
 	close(login_fd);
@@ -3929,7 +3939,7 @@ int do_init(int argc, char **argv) {
 //	set_termfunc(mmo_auth_sync);
 	set_defaultparse(parse_login);
 	login_fd = make_listen_port(login_port);
-	
+
 	if(anti_freeze_enable > 0) {
 		add_timer_func_list(char_anti_freeze_system, "char_anti_freeze_system");
 		i = add_timer_interval(gettick() + 1000, char_anti_freeze_system, 0, 0, ANTI_FREEZE_INTERVAL * 1000);
@@ -3957,7 +3967,7 @@ int do_init(int argc, char **argv) {
 		set_defaultconsoleparse(parse_console);
 	   	start_console();
 	}
-	
+
 	login_log("The login-server is ready (Server is listening on the port %d)." RETCODE, login_port);
 	printf("The login-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n", login_port);
 

+ 1 - 1
src/login/login.h

@@ -33,7 +33,7 @@ struct mmo_char_server {
 	short port;
 	int users;
 	int maintenance;
-	int new;
+	int new_;
 };
 
 extern struct mmo_char_server server[MAX_SERVERS];

+ 13 - 13
src/login_sql/login.c

@@ -161,7 +161,7 @@ struct dbt *online_db;
 
 void add_online_user(int account_id) {
     int *p;
-    p = aMalloc(sizeof(int));
+    p = (int*)aMalloc(sizeof(int));
     if (p == NULL) {
 		printf("add_online_user: memory allocation failure (malloc)!\n");
 		exit(0);
@@ -173,7 +173,7 @@ void add_online_user(int account_id) {
 int is_user_online(int account_id) {
     int *p;
 
-	p = numdb_search(online_db, account_id);
+	p = (int*)numdb_search(online_db, account_id);
 	if (p == NULL)
 		return 0;
 	printf("Acccount %d\n",*p);
@@ -182,8 +182,8 @@ int is_user_online(int account_id) {
 
 void remove_online_user(int account_id) {
     int *p;
-    p = numdb_erase(online_db,account_id);
-    free(p);
+    p = (int*)numdb_erase(online_db,account_id);
+    aFree(p);
 }
 
 //-----------------------------------------------------
@@ -238,9 +238,9 @@ int remove_control_chars(unsigned char *str) {
 //---------------------------------------------------
 // E-mail check: return 0 (not correct) or 1 (valid).
 //---------------------------------------------------
-int e_mail_check(unsigned char *email) {
+int e_mail_check(char *email) {
 	char ch;
-	unsigned char* last_arobas;
+	char* last_arobas;
 
 	// athena limits
 	if (strlen(email) < 3 || strlen(email) > 39)
@@ -394,7 +394,7 @@ int mmo_auth( struct mmo_account* account , int fd){
 
 	// auth start : time seed
 	gettimeofday(&tv, NULL);
-	strftime(tmpstr, 24, "%Y-%m-%d %H:%M:%S",localtime(&(tv.tv_sec)));
+	strftime(tmpstr, 24, "%Y-%m-%d %H:%M:%S",localtime((const time_t*)&(tv.tv_sec)));
 	sprintf(tmpstr+19, ".%03d", (int)tv.tv_usec/1000);
 
 	jstrescapecpy(t_uid,account->userid);
@@ -1217,7 +1217,7 @@ int parse_login(int fd) {
                             memcpy(WFIFOP(fd,47+server_num*32+6), server[i].name, 20);
                             WFIFOW(fd,47+server_num*32+26) = server[i].users;
                             WFIFOW(fd,47+server_num*32+28) = server[i].maintenance;
-                            WFIFOW(fd,47+server_num*32+30) = server[i].new;
+                            WFIFOW(fd,47+server_num*32+30) = server[i].new_;
                             server_num++;
                         }
                     }
@@ -1407,7 +1407,7 @@ int parse_login(int fd) {
 					memcpy(server[account.account_id].name,RFIFOP(fd,60),20);
 					server[account.account_id].users=0;
 					server[account.account_id].maintenance=RFIFOW(fd,82);
-					server[account.account_id].new=RFIFOW(fd,84);
+					server[account.account_id].new_=RFIFOW(fd,84);
 					server_fd[account.account_id]=fd;
 					if(anti_freeze_enable)
 						server_freezeflag[account.account_id] = 5; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed
@@ -1480,9 +1480,9 @@ int parse_console(char *buf) {
 
     printf("Type of command: %s || Command: %s \n",type,command);
 
-    if(buf) free(buf);
-    if(type) free(type);
-    if(command) free(command);
+    if(buf) aFree(buf);
+    if(type) aFree(type);
+    if(command) aFree(command);
 
     return 0;
 }
@@ -1841,7 +1841,7 @@ int do_init(int argc,char **argv){
 	}
 
 	// Online user database init
-    free(online_db);
+    aFree(online_db);
 	online_db = numdb_init();
 
 	printf("The login-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n", login_port);

+ 1 - 1
src/login_sql/login.h

@@ -34,7 +34,7 @@ struct mmo_char_server {
 	short port;
 	int users;
 	int maintenance;
-	int new;
+	int new_;
 };
 
 

+ 86 - 78
src/map/atcommand.c

@@ -8,6 +8,7 @@
 #include "../common/socket.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
+#include "../common/mmo.h"
 
 #include "log.h"
 #include "clif.h"
@@ -465,7 +466,7 @@ static AtCommandInfo atcommand_info[] = {
 	{ AtCommand_Send,				"@send",			60, atcommand_send },
 	{ AtCommand_SetBattleFlag,		"@setbattleflag",	60, atcommand_setbattleflag },
 	{ AtCommand_UnMute,				"@unmute",			60, atcommand_unmute }, // [Valaris]
-	{ AtCommand_Clearweather,		"@clearweather",	99, atcommand_clearweather }, // Dexity 
+	{ AtCommand_Clearweather,		"@clearweather",	99, atcommand_clearweather }, // Dexity
 	{ AtCommand_UpTime,				"@uptime",			 0, atcommand_uptime }, // by MC Cameri
 //	{ AtCommand_ChangeSex,			"@changesex",		 1, atcommand_changesex }, // by MC Cameri
 	{ AtCommand_Mute,				"@mute",			99, atcommand_mute }, // [celest]
@@ -531,8 +532,8 @@ static AtCommandInfo atcommand_info[] = {
  * This function return the name of the job (by [Yor])
  *----------------------------------------------------
  */
-char * job_name(int class) {
-	switch (class) {
+char * job_name(int class_) {
+	switch (class_) {
 	case 0:    return "Novice";
 	case 1:    return "Swordsman";
 	case 2:    return "Mage";
@@ -833,18 +834,18 @@ static int atmobsearch_sub(struct block_list *bl,va_list ap)
 	static int number=0;
 	struct mob_data *md;
 	char output[128];
-	
+
 	nullpo_retr(0, bl);
-	
+
 	if(!ap){
 		number=0;
 		return 0;
 	}
 	mob_id = va_arg(ap,int);
 	fd = va_arg(ap,int);
-	
+
 	md = (struct mob_data *)bl;
-	
+
 	if(md && fd && (mob_id==-1 || (md->class_==mob_id))){
 		snprintf(output, sizeof output, "%2d[%3d:%3d] %s",
 				++number,bl->x, bl->y,md->name);
@@ -894,7 +895,7 @@ void rehash( const int fd, struct map_session_data* sd )
         int map_id = 0;
 
         int LOADED_MAPS = map_num;
-	
+
         for (map_id = 0; map_id < LOADED_MAPS;map_id++) {
 
             if (map_id > LOADED_MAPS)
@@ -1023,7 +1024,7 @@ int atcommand_send(
 			WBUFW(buf,0)=0x18f;
 		case 4:
 			WBUFW(buf,0)=0x190;
-		}		
+		}
 	}
 	return 0;
 }
@@ -1113,7 +1114,7 @@ int atcommand_where(
 	snprintf(output, sizeof output, "%s %s %d %d",
 		character, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
 	clif_displaymessage(fd, output);
-	
+
 	return 0;
 }
 
@@ -1135,7 +1136,7 @@ int atcommand_jumpto(
 		clif_displaymessage(fd, "Please, enter a player name (usage: @jumpto/@warpto/@goto <char name>).");
 		return -1;
 	}
-	
+
 	memset(character, '\0', sizeof character);
 	if (sscanf(message, "%99[^\n]", character) < 1)
 		return -1;
@@ -1677,8 +1678,10 @@ int atcommand_whozeny(
 	int i, j, count,c;
 	char match_text[100];
 	char player_name[24];
-	int zeny[clif_countusers()];
-	int counted[clif_countusers()];
+	//int zeny[clif_countusers()];
+	//int counted[clif_countusers()];
+	int *zeny = (int *)aCallocA(clif_countusers(), sizeof(int));
+	int *counted = (int *)aCallocA(clif_countusers(), sizeof(int));
 
 	nullpo_retr(-1, sd);
 
@@ -1732,6 +1735,9 @@ int atcommand_whozeny(
 		clif_displaymessage(fd, output);
 	}
 
+	free(zeny);
+	free(counted);
+
 	return 0;
 }
 
@@ -1749,7 +1755,7 @@ int atcommand_happyhappyjoyjoy(
 	for (i = 0; i < fd_max; i++) {
 		if (session[i] && (pl_sd = session[i]->session_data) && pl_sd->state.auth) {
 			e=rand()%40;
-			if(e==34) 
+			if(e==34)
 				e = 0;
 			clif_emotion(&pl_sd->bl,e);
 		}
@@ -2177,7 +2183,7 @@ int atcommand_alive(
 	clif_resurrection(&sd->bl, 1);
 	clif_displaymessage(fd, msg_table[16]); // You've been revived! It's a miracle!
 	return 0;
-	} 
+	}
 	return -1;
 }
 
@@ -2296,8 +2302,8 @@ int atcommand_item(
 			if (pet_id >= 0) {
 				sd->catch_target_class = pet_db[pet_id].class_;
 				intif_create_pet(sd->status.account_id, sd->status.char_id,
-				                 pet_db[pet_id].class_, mob_db[pet_db[pet_id].class_].lv,
-				                 pet_db[pet_id].EggID, 0, pet_db[pet_id].intimate,
+				                 (short)pet_db[pet_id].class_, (short)mob_db[pet_db[pet_id].class_].lv,
+				                 (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
 				                 100, 0, 1, pet_db[pet_id].jname);
 			// if not pet egg
 			} else {
@@ -2447,7 +2453,7 @@ int atcommand_baselevelup(
 			clif_displaymessage(fd, msg_table[47]); // Base level can't go any higher.
 			return -1;
 		}	// End Addition
-		if (level > battle_config.maximum_level || level > (battle_config.maximum_level - sd->status.base_level)) // fix positiv overflow
+		if ((unsigned int)level > battle_config.maximum_level || (unsigned int)level > (battle_config.maximum_level - sd->status.base_level)) // fix positiv overflow
 			level = battle_config.maximum_level - sd->status.base_level;
 		for (i = 1; i <= level; i++)
 			sd->status.status_point += (sd->status.base_level + i + 14) / 5;
@@ -2464,7 +2470,7 @@ int atcommand_baselevelup(
 			clif_displaymessage(fd, msg_table[158]); // Base level can't go any lower.
 			return -1;
 		}
-		if (level < -battle_config.maximum_level || level < (1 - sd->status.base_level)) // fix negativ overflow
+		if (level < -(int)battle_config.maximum_level || level < (1 - (int)sd->status.base_level)) // fix negativ overflow
 			level = 1 - sd->status.base_level;
 		if (sd->status.status_point > 0) {
 			for (i = 0; i > level; i--)
@@ -2491,7 +2497,8 @@ int atcommand_joblevelup(
 	const int fd, struct map_session_data* sd,
 	const char* command, const char* message)
 {
-	int up_level = 50, level;
+	unsigned int up_level = 50;
+	int level;
 	struct pc_base_job s_class;
 	nullpo_retr(-1, sd);
 	s_class = pc_calc_base_job(sd->status.class_);
@@ -2514,7 +2521,7 @@ int atcommand_joblevelup(
 			clif_displaymessage(fd, msg_table[23]); // Job level can't go any higher.
 			return -1;
 		}
-		if (level > up_level || level > (up_level - sd->status.job_level)) // fix positiv overflow
+		if ((unsigned int)level > up_level || (unsigned int)level > (up_level - sd->status.job_level)) // fix positiv overflow
 			level = up_level - sd->status.job_level;
 		sd->status.job_level += level;
 		clif_updatestatus(sd, SP_JOBLEVEL);
@@ -2529,7 +2536,7 @@ int atcommand_joblevelup(
 			clif_displaymessage(fd, msg_table[159]); // Job level can't go any lower.
 			return -1;
 		}
-		if (level < -up_level || level < (1 - sd->status.job_level)) // fix negativ overflow
+		if (level < -(int)up_level || level < (1 - (int)sd->status.job_level)) // fix negativ overflow
 			level = 1 - sd->status.job_level;
 		sd->status.job_level += level;
 		clif_updatestatus(sd, SP_JOBLEVEL);
@@ -3117,7 +3124,7 @@ int atcommand_monster(
 		printf("%s monster='%s' name='%s' id=%d count=%d (%d,%d)\n", command, monster, name, mob_id, number, x, y);
 
 	count = 0;
-	range = sqrt(number) / 2;
+	range = (int)sqrt(number) / 2;
 	range = range * 2 + 5; // calculation of an odd number (+ 4 area around)
 	for (i = 0; i < number; i++) {
 		j = 0;
@@ -3209,7 +3216,7 @@ int atcommand_spawn(
 		printf("%s monster='%s' name='%s' id=%d count=%d (%d,%d)\n", command, monster, name, mob_id, number, x, y);
 
 	count = 0;
-	range = sqrt(number) / 2;
+	range = (int)sqrt(number) / 2;
 	range = range * 2 + 5; // calculation of an odd number (+ 4 area around)
 	for (i = 0; i < number; i++) {
 		j = 0;
@@ -3848,9 +3855,9 @@ int atcommand_param(
 	}
 
 	new_value = (int)*status[index] + value;
-	if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow
+	if (value > 0 && ((unsigned int)value > battle_config.max_parameter || (unsigned int)new_value > battle_config.max_parameter)) // fix positiv overflow
 		new_value = battle_config.max_parameter;
-	else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow
+	else if (value < 0 && (value < -(int)battle_config.max_parameter || new_value < 1)) // fix negativ overflow
 		new_value = 1;
 
 	if (new_value != (int)*status[index]) {
@@ -3893,9 +3900,9 @@ int atcommand_stat_all(
 	for (index = 0; index < (int)(sizeof(status) / sizeof(status[0])); index++) {
 
 		new_value = (int)*status[index] + value;
-		if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow
+		if (value > 0 && ((unsigned int)value > battle_config.max_parameter || (unsigned int)new_value > battle_config.max_parameter)) // fix positiv overflow
 			new_value = battle_config.max_parameter;
-		else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow
+		else if (value < 0 && (value < -(int)battle_config.max_parameter || new_value < 1)) // fix negativ overflow
 			new_value = 1;
 
 		if (new_value != (int)*status[index]) {
@@ -3993,8 +4000,8 @@ int atcommand_makeegg(
 		sd->catch_target_class = pet_db[pet_id].class_;
 		intif_create_pet(
 			sd->status.account_id, sd->status.char_id,
-			pet_db[pet_id].class_, mob_db[pet_db[pet_id].class_].lv,
-			pet_db[pet_id].EggID, 0, pet_db[pet_id].intimate,
+			(short)pet_db[pet_id].class_, (short)mob_db[pet_db[pet_id].class_].lv,
+			(short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
 			100, 0, 1, pet_db[pet_id].jname);
 	} else {
 		clif_displaymessage(fd, msg_table[180]); // The monter/egg name/id doesn't exist.
@@ -4149,14 +4156,14 @@ atcommand_recall(
 	char character[100];
 	char output[200];
 	struct map_session_data *pl_sd = NULL;
-	
+
 	nullpo_retr(-1, sd);
 
 	if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) {
 		clif_displaymessage(fd, "Please, enter a player name (usage: @recall <char name>).");
 		return -1;
 	}
-	
+
 	memset(character, '\0', sizeof character);
 	if(sscanf(message, "%99[^\n]", character) < 1)
 		return -1;
@@ -4658,7 +4665,7 @@ int atcommand_character_baselevel(
 					clif_displaymessage(fd, msg_table[91]); // Character's base level can't go any higher.
 					return 0;
 				}	// End Addition
-				if (level > battle_config.maximum_level || level > (battle_config.maximum_level - pl_sd->status.base_level)) // fix positiv overflow
+				if ((unsigned int)level > battle_config.maximum_level || (unsigned int)level > (battle_config.maximum_level - pl_sd->status.base_level)) // fix positiv overflow
 					level = battle_config.maximum_level - pl_sd->status.base_level;
 				for (i = 1; i <= level; i++)
 					pl_sd->status.status_point += (pl_sd->status.base_level + i + 14) / 5;
@@ -4675,7 +4682,7 @@ int atcommand_character_baselevel(
 					clif_displaymessage(fd, msg_table[193]); // Character's base level can't go any lower.
 					return -1;
 				}
-				if (level < -battle_config.maximum_level || level < (1 - pl_sd->status.base_level)) // fix negativ overflow
+				if (level < -(int)battle_config.maximum_level || level < (1 - (int)pl_sd->status.base_level)) // fix negativ overflow
 					level = 1 - pl_sd->status.base_level;
 				if (pl_sd->status.status_point > 0) {
 					for (i = 0; i > level; i--)
@@ -4712,7 +4719,8 @@ int atcommand_character_joblevel(
 {
 	struct map_session_data *pl_sd;
 	char character[100];
-	int max_level = 50, level = 0;
+	unsigned int max_level = 50;
+	int level = 0;
 	//転生や養子の場合の元の職業を算出する
 	struct pc_base_job pl_s_class;
 	nullpo_retr(-1, sd);
@@ -5195,7 +5203,7 @@ int atcommand_idsearch(
 {
 	char item_name[100];
 	char output[200];
-	int i, match;
+	unsigned int i, match;
 	struct item_data *item;
 	nullpo_retr(-1, sd);
 
@@ -5652,7 +5660,7 @@ int atcommand_reloadscript(
 	nullpo_retr(-1, sd);
 	atcommand_broadcast( fd, sd, "@broadcast", "eAthena SQL Server is Rehashing..." );
 	atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" );
-	
+
         rehash( fd, sd );
 
 	atcommand_broadcast( fd, sd, "@broadcast", "Reloading NPCs..." );
@@ -6090,7 +6098,7 @@ int atcommand_enablenpc(const int fd, struct map_session_data* sd,
 	memset(NPCname, '\0', sizeof(NPCname));
 
 	if (!message || !*message || sscanf(message, "%99[^\n]", NPCname) < 1) {
-		clif_displaymessage(fd, "Please, enter a NPC name (usage: @npcon <NPC_name>).");
+		clif_displaymessage(fd, "Please, enter a NPC name (usage: @enablenpc <NPC_name>).");
 		return -1;
 	}
 
@@ -6961,7 +6969,7 @@ atcommand_npcmove(const int fd, struct map_session_data* sd,
 	int x = 0, y = 0;
 	struct npc_data *nd = 0;
 	nullpo_retr(-1, sd);
-	
+
 
 	if (!message || !*message)
 		return -1;
@@ -7010,7 +7018,7 @@ atcommand_addwarp(const int fd, struct map_session_data* sd,
 
 	ret = npc_parse_warp(w1, "warp", w3, w4);
 
-	sprintf(output, "New warp NPC => %s",w3); 
+	sprintf(output, "New warp NPC => %s",w3);
 
 	clif_displaymessage(fd, output);
 
@@ -7063,7 +7071,7 @@ atcommand_dropall(const int fd, struct map_session_data* sd,
 }
 /*==========================================
  * @chardropall by [MouseJstr]
- * 
+ *
  * Throw all the characters possessions on the ground.  Normally
  * done in response to them being disrespectful of a GM
  *------------------------------------------
@@ -7139,7 +7147,7 @@ atcommand_charstoreall(const int fd, struct map_session_data* sd,
 
 	if (!message || !*message)
 		return -1;
-	if((pl_sd=map_nick2sd((char *) message)) == NULL) 
+	if((pl_sd=map_nick2sd((char *) message)) == NULL)
 		return -1;
 
 	if (storage_storageopen(pl_sd) == 1) {
@@ -7254,7 +7262,7 @@ atcommand_skilltree(const int fd, struct map_session_data* sd,
     clif_displaymessage(fd, "Usage: @skilltree <skillnum> <target>");
     return -1;
   }
-  if((pl_sd=map_nick2sd(target)) == NULL) 
+  if((pl_sd=map_nick2sd(target)) == NULL)
     return -1;
 
   s_class = pc_calc_base_job(pl_sd->status.class_);
@@ -7265,8 +7273,8 @@ atcommand_skilltree(const int fd, struct map_session_data* sd,
 
   tbl = job_name(c);
 
-  sprintf(output, "Player is using %s %s skill tree (%d basic points)",  
-	  s_class.upper ? "upper" : "lower", 
+  sprintf(output, "Player is using %s %s skill tree (%d basic points)",
+	  s_class.upper ? "upper" : "lower",
 	  tbl, pc_checkskill(pl_sd, 1));
   clif_displaymessage(fd, output);
 
@@ -7276,7 +7284,7 @@ atcommand_skilltree(const int fd, struct map_session_data* sd,
       break;
     }
   }
- 
+
   if (skillidx == -1) {
     sprintf(output, "I do not believe the player can use that skill");
     clif_displaymessage(fd, output);
@@ -7285,19 +7293,19 @@ atcommand_skilltree(const int fd, struct map_session_data* sd,
 
   ent = &skill_tree[s][c][skillidx];
 
-  for(j=0;j<5;j++) 
+  for(j=0;j<5;j++)
     if( ent->need[j].id &&
-	pc_checkskill(sd,ent->need[j].id) < ent->need[j].lv) 
+	pc_checkskill(sd,ent->need[j].id) < ent->need[j].lv)
       {
 	int idx = 0;
 	char *desc;
-        while (skill_names[idx].id != 0 && skill_names[idx].id != ent->need[j].id) 
+        while (skill_names[idx].id != 0 && skill_names[idx].id != ent->need[j].id)
 		idx++;
 	if (skill_names[idx].id == 0)
 		desc = "Unknown skill";
 	else
 		desc = skill_names[idx].desc;
-	sprintf(output, "player requires level %d of skill %s",  
+	sprintf(output, "player requires level %d of skill %s",
 		ent->need[j].lv,  desc);
 	clif_displaymessage(fd, output);
 	meets = 0;
@@ -7307,7 +7315,7 @@ atcommand_skilltree(const int fd, struct map_session_data* sd,
     sprintf(output, "I believe the player meets all the requirements for that skill");
     clif_displaymessage(fd, output);
   }
-            
+
   return 0;
 }
 
@@ -7392,7 +7400,7 @@ atcommand_rings(const int fd, struct map_session_data* sd,
 {
   struct item item_tmp;
   int flag;
-  
+
   memset(&item_tmp, 0, sizeof(item_tmp));
 
   item_tmp.nameid = 2634;
@@ -7456,7 +7464,7 @@ atcommand_grind(const int fd, struct map_session_data* sd,
 		clif_displaymessage(fd, "Usage: @grind  <target>");
 		return -1;
 	}
-	if((pl_sd=map_nick2sd(target)) == NULL) 
+	if((pl_sd=map_nick2sd(target)) == NULL)
 		return -1;
 
 	for (skillnum = 1; skillnum < 500; skillnum++) {
@@ -7512,7 +7520,7 @@ atcommand_rain(
 	} else {
 		map[sd->bl.m].flag.rain=1;
 		clif_specialeffect(&sd->bl,effno,2);
-		clif_displaymessage(fd, "It is made to rain.");		
+		clif_displaymessage(fd, "It is made to rain.");
 	}
 	return 0;
 }
@@ -7536,7 +7544,7 @@ atcommand_snow(
 		clif_specialeffect(&sd->bl,effno,2);
 		clif_displaymessage(fd, "It is made to snow.");
 	}
-	
+
 	return 0;
 }
 
@@ -7629,7 +7637,7 @@ atcommand_clearweather(
 	map[sd->bl.m].flag.leaves=0;
 	//clif_specialeffect(&sd->bl,effno,2); // not required. [celest]
 	return 0;
-} 
+}
 
 /*===============================================================
  * Sound Command - plays a sound for everyone! [Codemaster]
@@ -7720,7 +7728,7 @@ atcommand_cleanmap(
 }
 
 /*==========================================
- * 
+ *
  *------------------------------------------
  */
 int
@@ -7735,14 +7743,14 @@ atcommand_summon(
 	int id = 0;
 	struct mob_data *md;
 	unsigned int tick=gettick();
-	
+
 	nullpo_retr(-1, sd);
 
 	if (!message || !*message)
 		return -1;
 	if (sscanf(message, "%99s", name) < 1)
 		return -1;
-	
+
 	if ((mob_id = atoi(name)) == 0)
 		mob_id = mobdb_searchname(name);
 	if(mob_id == 0)
@@ -7823,7 +7831,7 @@ atcommand_adjgmlvl(
         return -1;
     }
 
-    if((pl_sd=map_nick2sd((char *) user)) == NULL) 
+    if((pl_sd=map_nick2sd((char *) user)) == NULL)
         return -1;
 
     pc_set_gm_level(pl_sd->status.account_id, newlev);
@@ -7837,7 +7845,7 @@ atcommand_adjgmlvl(
  *
  * Open a trade window with a remote player
  *
- * If I have to jump to a remote player one more time, I am 
+ * If I have to jump to a remote player one more time, I am
  * gonna scream!
  *------------------------------------------
  */
@@ -7876,7 +7884,7 @@ atcommand_setbattleflag(
         	return -1;
     	}
 
-	if (battle_set_value(flag, value) == 0) 
+	if (battle_set_value(flag, value) == 0)
         	clif_displaymessage(fd, "unknown battle_config flag");
 	else
         	clif_displaymessage(fd, "battle_config set as requested");
@@ -7901,7 +7909,7 @@ int atcommand_unmute(
 	if((pl_sd=map_nick2sd((char *) message)) != NULL) {
 		if(pl_sd->sc_data[SC_NOCHAT].timer!=-1) {
 			pl_sd->status.manner = 0; // have to set to 0 first [celest]
-			skill_status_change_end(&pl_sd->bl,SC_NOCHAT,-1); 
+			skill_status_change_end(&pl_sd->bl,SC_NOCHAT,-1);
 			clif_displaymessage(sd->fd,"Player unmuted");
 		}
 		else
@@ -7932,7 +7940,7 @@ atcommand_uptime(
 	seconds -= (seconds/hour>0)?(seconds/hour)*hour:0;
 	minutes = seconds/minute;
 	seconds -= (seconds/minute>0)?(seconds/minute)*minute:0;
-	
+
         snprintf(output, sizeof(output), msg_table[245], days, hours, minutes, seconds);
 
 	clif_displaymessage(fd,output);
@@ -8013,7 +8021,7 @@ atcommand_petid(const int fd, struct map_session_data* sd,
 	char temp0[100];
 	char temp1[100];
 	int cnt = 0, i = 0;
-	
+
 	nullpo_retr(-1, sd);
 
 	if (!message || !*message)
@@ -8066,7 +8074,7 @@ atcommand_identify(
 		}
 	}
 	if (num > 0) {
-		clif_item_identify_list(sd);	
+		clif_item_identify_list(sd);
 	} else {
 		clif_displaymessage(fd,"There are no items to appraise.");
 	}
@@ -8074,7 +8082,7 @@ atcommand_identify(
 }
 
 /*==========================================
- * @gmotd (Global MOTD) 
+ * @gmotd (Global MOTD)
  * by davidsiaw :P
  *------------------------------------------
  */
@@ -8113,7 +8121,7 @@ int atcommand_misceffect(
 	if (sscanf(message, "%d", &effect) < 1)
 		return -1;
 	clif_misceffect(&sd->bl,effect);
-	
+
 	return 0;
 }
 
@@ -8128,7 +8136,7 @@ int charid2sessionid(int charid)
          if (pl_sd->status.char_id==charid) { session_id = i; break; }
       }
    }
-   
+
    return session_id;
 }
 
@@ -8143,7 +8151,7 @@ int accountid2sessionid(int accountid)
          if (pl_sd->status.account_id==accountid) { session_id = i; break; }
       }
    }
-   
+
    return session_id;
 }
 
@@ -8696,9 +8704,9 @@ atcommand_charkillableid(
    {
       if((pl_sd=session[session_id]->session_data) == NULL)
                    return -1;
-   
+
       pl_sd->special_state.killable = !pl_sd->special_state.killable;
-   
+
       if(pl_sd->special_state.killable)
         clif_displaymessage(fd, "The player is now killable");
            else
@@ -8737,9 +8745,9 @@ atcommand_charkillableid2(
    {
       if((pl_sd=session[session_id]->session_data) == NULL)
                    return -1;
-   
+
       pl_sd->special_state.killable = !pl_sd->special_state.killable;
-   
+
       if(pl_sd->special_state.killable)
         clif_displaymessage(fd, "The player is now killable");
            else
@@ -8762,7 +8770,7 @@ atcommand_charkillableid2(
 int atcommand_listmail(
 	const int fd, struct map_session_data* sd,
 	const char* command, const char* message)
-{ 
+{
 	if(!battle_config.mail_system)
 		return 0;
 
@@ -8772,7 +8780,7 @@ int atcommand_listmail(
 		mail_check(sd,3);
 	else if(strlen(command)==9)
 		mail_check(sd,2);
-	else 
+	else
 		mail_check(sd,1);
 	return 0;
 }
@@ -8823,7 +8831,7 @@ int atcommand_sendmail(
 
 	if(strlen(command)==17)
 		mail_send(sd,name,text,1);
-	else 
+	else
 		mail_send(sd,name,text,0);
 
 	return 0;
@@ -8842,7 +8850,7 @@ int atcommand_refreshonline(
 	nullpo_retr(-1, sd);
 
 	char_online_check();
-	
+
 	return 0;
 }
 

+ 5 - 5
src/map/atcommand.h

@@ -112,9 +112,9 @@ enum AtCommandType {
 	AtCommand_CharSkReset,
 	AtCommand_CharStReset,
 	//by chbrules
-	AtCommand_CharModel, 
+	AtCommand_CharModel,
 	AtCommand_CharSKPoint,
-	AtCommand_CharSTPoint, 
+	AtCommand_CharSTPoint,
 //	AtCommand_CharZeny, //now #zeny
 	AtCommand_RecallAll,
 	AtCommand_ReloadItemDB,
@@ -198,7 +198,7 @@ enum AtCommandType {
 	AtCommand_CleanMap,
 
 	// SQL-only commands start
-#ifndef TXT_ONLY 
+#ifndef TXT_ONLY
 	AtCommand_CheckMail, // [Valaris]
 	AtCommand_ListMail, // [Valaris]
 	AtCommand_ListNewMail, // [Valaris]
@@ -206,7 +206,7 @@ enum AtCommandType {
 	AtCommand_SendMail, // [Valaris]
 	AtCommand_DeleteMail, // [Valaris]
 	AtCommand_SendPriorityMail, // [Valaris]
-//	AtCommand_Sound, // [Valaris]	
+//	AtCommand_Sound, // [Valaris]
 	AtCommand_RefreshOnline, // [Valaris]
 	// SQL-only commands end
 #endif
@@ -272,7 +272,7 @@ int msg_config_read(const char *cfgName);
 
 char *estr_lower(char *str);
 
-char * job_name(int class);
+char * job_name(int class_);
 int e_mail_check(unsigned char *email);
 
 #endif

+ 110 - 59
src/map/battle.c

@@ -179,6 +179,10 @@ int battle_get_max_hp(struct block_list *bl)
 			if(sc_data[SC_APPLEIDUN].timer!=-1)
 				max_hp += ((5+sc_data[SC_APPLEIDUN].val1*2+((sc_data[SC_APPLEIDUN].val2+1)>>1)
 						+sc_data[SC_APPLEIDUN].val3/10) * max_hp)/100;
+			if(sc_data[SC_GOSPEL].timer!=-1 &&
+				sc_data[SC_GOSPEL].val4 == BCT_PARTY &&
+				sc_data[SC_GOSPEL].val3 == 4)
+				max_hp += max_hp * 25 / 100;
 		}
 		if(max_hp < 1) max_hp = 1;
 		return max_hp;
@@ -429,16 +433,24 @@ int battle_get_flee(struct block_list *bl)
 	else
 		flee=battle_get_agi(bl) + battle_get_lv(bl);
 
-	if(sc_data) {
-		if(sc_data[SC_WHISTLE].timer!=-1 && bl->type != BL_PC)
+	if(bl->type != BL_PC && sc_data){
+		if(sc_data[SC_WHISTLE].timer!=-1)
 			flee += flee*(sc_data[SC_WHISTLE].val1+sc_data[SC_WHISTLE].val2
 					+(sc_data[SC_WHISTLE].val3>>16))/100;
-		if(sc_data[SC_BLIND].timer!=-1 && bl->type != BL_PC)
+		if(sc_data[SC_BLIND].timer!=-1)
 			flee -= flee*25/100;
-		if(sc_data[SC_WINDWALK].timer!=-1 && bl->type != BL_PC) // ウィンドウォーク
+		if(sc_data[SC_WINDWALK].timer!=-1) // ウィンドウォーク
 			flee += flee*(sc_data[SC_WINDWALK].val2)/100;
-		if(sc_data[SC_SPIDERWEB].timer!=-1 && bl->type != BL_PC) //スパイダーウェブ
+		if(sc_data[SC_SPIDERWEB].timer!=-1) //スパイダーウェブ
 			flee -= flee*50/100;
+		if(sc_data[SC_GOSPEL].timer!=-1) {
+			if (sc_data[SC_GOSPEL].val4 == BCT_PARTY &&
+				sc_data[SC_GOSPEL].val3 == 13)
+				flee += flee*5/100;
+			else if (sc_data[SC_GOSPEL].val4 == BCT_ENEMY &&
+				sc_data[SC_GOSPEL].val3 == 7)
+				flee = 0;
+		}
 	}
 	if(flee < 1) flee = 1;
 	return flee;
@@ -460,16 +472,20 @@ int battle_get_hit(struct block_list *bl)
 	else
 		hit=battle_get_dex(bl) + battle_get_lv(bl);
 
-	if(sc_data) {
-		if(sc_data[SC_HUMMING].timer!=-1 && bl->type != BL_PC)	//
+	if(bl->type != BL_PC && sc_data) {
+		if(sc_data[SC_HUMMING].timer!=-1)	//
 			hit += hit*(sc_data[SC_HUMMING].val1*2+sc_data[SC_HUMMING].val2
 					+sc_data[SC_HUMMING].val3)/100;
-		if(sc_data[SC_BLIND].timer!=-1 && bl->type != BL_PC)		// 呪い
+		if(sc_data[SC_BLIND].timer!=-1)		// 呪い
 			hit -= hit*25/100;
-		if(sc_data[SC_TRUESIGHT].timer!=-1 && bl->type != BL_PC)		// トゥルーサイト
+		if(sc_data[SC_TRUESIGHT].timer!=-1)		// トゥルーサイト
 			hit += 3*(sc_data[SC_TRUESIGHT].val1);
-		if(sc_data[SC_CONCENTRATION].timer!=-1 && bl->type != BL_PC) //コンセントレーション
+		if(sc_data[SC_CONCENTRATION].timer!=-1) //コンセントレーション
 			hit += (hit*(10*(sc_data[SC_CONCENTRATION].val1)))/100;
+		if(sc_data[SC_GOSPEL].timer!=-1 &&
+			sc_data[SC_GOSPEL].val4 == BCT_PARTY &&
+			sc_data[SC_GOSPEL].val3 == 14)
+			hit += hit*5/100;
 	}
 	if(hit < 1) hit = 1;
 	return hit;
@@ -560,7 +576,7 @@ int battle_get_baseatk(struct block_list *bl)
 		if(sc_data[SC_CURSE].timer!=-1 ) //呪われていたら
 			batk -= batk*25/100; //base_atkが25%減少
 		if(sc_data[SC_CONCENTRATION].timer!=-1 && bl->type != BL_PC) //コンセントレーション
-			batk += batk*(5*sc_data[SC_CONCENTRATION].val1)/100;		
+			batk += batk*(5*sc_data[SC_CONCENTRATION].val1)/100;
 	}
 	if(batk < 1) batk = 1; //base_atkは最低でも1
 	return batk;
@@ -584,13 +600,22 @@ int battle_get_atk(struct block_list *bl)
 	else if(bl->type==BL_PET && (struct pet_data *)bl)
 		atk = mob_db[((struct pet_data*)bl)->class_].atk1;
 
-	if(sc_data) {
-		if(sc_data[SC_PROVOKE].timer!=-1 && bl->type != BL_PC)
+	if(bl->type != BL_PC && sc_data) {
+		if(sc_data[SC_PROVOKE].timer!=-1)
 			atk = atk*(100+2*sc_data[SC_PROVOKE].val1)/100;
-		if(sc_data[SC_CURSE].timer!=-1 )
+		if(sc_data[SC_CURSE].timer!=-1)
 			atk -= atk*25/100;
-		if(sc_data[SC_CONCENTRATION].timer!=-1 && bl->type != BL_PC) //コンセントレーション
+		if(sc_data[SC_CONCENTRATION].timer!=-1) //コンセントレーション
 			atk += atk*(5*sc_data[SC_CONCENTRATION].val1)/100;
+
+		if(sc_data[SC_GOSPEL].timer!=-1) {
+			if (sc_data[SC_GOSPEL].val4 == BCT_PARTY &&
+				sc_data[SC_GOSPEL].val3 == 12)
+				atk += atk*8/100;
+			else if (sc_data[SC_GOSPEL].val4 == BCT_ENEMY &&
+				sc_data[SC_GOSPEL].val3 == 6)
+				atk = 0;
+		}
 	}
 	if(atk < 0) atk = 0;
 	return atk;
@@ -605,9 +630,6 @@ int battle_get_atk_(struct block_list *bl)
 	nullpo_retr(0, bl);
 	if(bl->type==BL_PC && (struct map_session_data *)bl){
 		int atk=((struct map_session_data*)bl)->watk_;
-
-		if(((struct map_session_data *)bl)->sc_data[SC_CURSE].timer!=-1 )
-			atk -= atk*25/100;
 		return atk;
 	}
 	else
@@ -780,10 +802,19 @@ int battle_get_def(struct block_list *bl)
 					def = def * (100 - sc_data[SC_SIGNUMCRUCIS].val2)/100;
 				//永遠の混沌時はDEF0になる
 				if(sc_data[SC_ETERNALCHAOS].timer!=-1)
-					def = 0;			
+					def = 0;
 				//コンセントレーション時は減算
 				if( sc_data[SC_CONCENTRATION].timer!=-1)
 					def = (def*(100 - 5*sc_data[SC_CONCENTRATION].val1))/100;
+
+				if(sc_data[SC_GOSPEL].timer!=-1) {
+					if (sc_data[SC_GOSPEL].val4 == BCT_PARTY &&
+						sc_data[SC_GOSPEL].val3 == 11)
+						def += def*25/100;
+					else if (sc_data[SC_GOSPEL].val4 == BCT_ENEMY &&
+						sc_data[SC_GOSPEL].val3 == 5)
+						def = 0;
+				}
 			}
 		}
 		//詠唱中は詠唱時減算率に基づいて減算
@@ -859,6 +890,15 @@ int battle_get_def2(struct block_list *bl)
 		//コンセントレーション時は減算
 		if( sc_data[SC_CONCENTRATION].timer!=-1)
 			def2 = def2*(100 - 5*sc_data[SC_CONCENTRATION].val1)/100;
+
+		if(sc_data[SC_GOSPEL].timer!=-1) {
+			if (sc_data[SC_GOSPEL].val4 == BCT_PARTY &&
+				sc_data[SC_GOSPEL].val3 == 11)
+				def2 += def2*25/100;
+			else if (sc_data[SC_GOSPEL].val4 == BCT_ENEMY &&
+				sc_data[SC_GOSPEL].val3 == 5)
+				def2 = 0;
+		}
 	}
 	if(def2 < 1) def2 = 1;
 	return def2;
@@ -942,6 +982,10 @@ int battle_get_speed(struct block_list *bl)
 				speed = speed*150/100;
 			if(sc_data[SC_SPEEDUP0].timer!=-1)
 				speed -= speed*25/100;
+			if(sc_data[SC_GOSPEL].timer!=-1 &&
+				sc_data[SC_GOSPEL].val4 == BCT_ENEMY &&
+				sc_data[SC_GOSPEL].val3 == 8)
+				speed = speed*125/100;
 		}
 		if(speed < 1) speed = 1;
 		return speed;
@@ -1002,6 +1046,10 @@ int battle_get_adelay(struct block_list *bl)
 			//ディフェンダー時は加算
 			if(sc_data[SC_DEFENDER].timer != -1)
 				adelay += (1100 - sc_data[SC_DEFENDER].val1*100);
+			if(sc_data[SC_GOSPEL].timer!=-1 &&
+				sc_data[SC_GOSPEL].val4 == BCT_ENEMY &&
+				sc_data[SC_GOSPEL].val3 == 8)
+				aspd_rate = aspd_rate*125/100;
 		}
 		if(aspd_rate != 100)
 			adelay = adelay*aspd_rate/100;
@@ -1315,7 +1363,7 @@ int battle_delay_damage_sub(int tid,unsigned int tick,int id,int data)
 	struct battle_delay_damage_ *dat=(struct battle_delay_damage_ *)data;
 	if( dat && map_id2bl(id)==dat->src && dat->target->prev!=NULL)
 		battle_damage(dat->src,dat->target,dat->damage,dat->flag);
-	free(dat);
+	aFree(dat);
 	return 0;
 }
 int battle_delay_damage(unsigned int tick,struct block_list *src,struct block_list *target,int damage,int flag)
@@ -1487,11 +1535,11 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,int damage,i
 	struct mob_data *md=NULL;
 	struct status_change *sc_data,*sc;
 	short *sc_count;
-	int class;
+	int class_;
 
 	nullpo_retr(0, bl);
 
-	class = battle_get_class(bl);
+	class_ = battle_get_class(bl);
 	if(bl->type==BL_MOB) md=(struct mob_data *)bl;
 	else sd=(struct map_session_data *)bl;
 
@@ -1612,7 +1660,10 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,int damage,i
 		}
 		// リジェクトソード
 		if(sc_data[SC_REJECTSWORD].timer!=-1 && damage > 0 && flag&BF_WEAPON &&
-		  ((src->type==BL_PC && ((struct map_session_data *)src)->status.weapon == (1 || 2 || 3)) || src->type==BL_MOB )){
+			// Fixed the condition check [Aalye]
+			(src->type==BL_MOB || (src->type==BL_PC && (((struct map_session_data *)src)->status.weapon == 1 ||
+			((struct map_session_data *)src)->status.weapon == 2 ||
+			((struct map_session_data *)src)->status.weapon == 3)))){
 			if(rand()%100 < (15*sc_data[SC_REJECTSWORD].val1)){ //反射確率は15*Lv
 				damage = damage*50/100;
 				clif_damage(bl,src,gettick(),0,0,damage,0,0,0);
@@ -1630,22 +1681,22 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,int damage,i
 				damage<<=1;
 				skill_status_change_end(bl, SC_SPIDERWEB, -1);
 			}
-		
+
 		if(sc_data[SC_FOGWALL].timer != -1 && flag&BF_MAGIC)
 			if(rand()%100 < sc_data[SC_FOGWALL].val2)
 				damage = 0;
 	}
 
-	if(class == 1288 || class == 1287 || class == 1286 || class == 1285) {
-//	if(class == 1288) {
-		if(class == 1288 && flag&BF_SKILL)
+	if(class_ == 1288 || class_ == 1287 || class_ == 1286 || class_ == 1285) {
+//	if(class_ == 1288) {
+		if(class_ == 1288 && flag&BF_SKILL)
 			damage=0;
 		if(src->type == BL_PC) {
 			struct guild *g=guild_search(((struct map_session_data *)src)->status.guild_id);
 			struct guild_castle *gc=guild_mapname2gc(map[bl->m].name);
 			if(!((struct map_session_data *)src)->status.guild_id)
 				damage=0;
-			if(gc && agit_flag==0 && class != 1288)	// guardians cannot be damaged during non-woe [Valaris]
+			if(gc && agit_flag==0 && class_ != 1288)	// guardians cannot be damaged during non-woe [Valaris]
 				damage=0;  // end woe check [Valaris]
 			if(g == NULL)
 				damage=0;//ギルド未加入ならダメージ無し
@@ -2010,7 +2061,7 @@ static struct Damage battle_calc_pet_weapon_attack(
 				blewcount=0;
 				break;
 			case AS_GRIMTOOTH:
-				damage = damage*(100+ 20*skill_lv)/100;         
+				damage = damage*(100+ 20*skill_lv)/100;
 				break;
 			case AS_POISONREACT: // celest
 				s_ele = 0;
@@ -2208,7 +2259,7 @@ static struct Damage battle_calc_pet_weapon_attack(
 			hitrate -= 50;
 		if (t_sc_data[SC_SLEEP].timer!=-1 ||	// 睡眠は必中
 			t_sc_data[SC_STAN].timer!=-1 ||		// スタンは必中
-			t_sc_data[SC_FREEZE].timer!=-1 || 
+			t_sc_data[SC_FREEZE].timer!=-1 ||
 			(t_sc_data[SC_STONE].timer!=-1 && t_sc_data[SC_STONE].val2==0))	// 凍結は必中
 			hitrate = 1000000;
 	}
@@ -2221,7 +2272,7 @@ static struct Damage battle_calc_pet_weapon_attack(
 		dmg_lv = ATK_DEF;
 	}
 
-	
+
 	if(t_sc_data) {
 		int cardfix=100;
 		if(t_sc_data[SC_DEFENDER].timer != -1 && flag&BF_LONG)
@@ -2507,7 +2558,7 @@ static struct Damage battle_calc_mob_weapon_attack(
 				flag=(flag&~BF_SKILLMASK)|BF_NORMAL;
 				break;
 			case AS_GRIMTOOTH:
-				damage = damage*(100+ 20*skill_lv)/100;         
+				damage = damage*(100+ 20*skill_lv)/100;
 				break;
 			case AS_POISONREACT: // celest
 				s_ele = 0;
@@ -2710,7 +2761,7 @@ static struct Damage battle_calc_mob_weapon_attack(
 			hitrate -= 50;
 		if (t_sc_data[SC_SLEEP].timer!=-1 ||	// 睡眠は必中
 			t_sc_data[SC_STAN].timer!=-1 ||		// スタンは必中
-			t_sc_data[SC_FREEZE].timer!=-1 || 
+			t_sc_data[SC_FREEZE].timer!=-1 ||
 			(t_sc_data[SC_STONE].timer!=-1 && t_sc_data[SC_STONE].val2==0))	// 凍結は必中
 			hitrate = 1000000;
 	}
@@ -2762,8 +2813,8 @@ static struct Damage battle_calc_mob_weapon_attack(
 	if(damage < 0) damage = 0;
 
 	// 属 性の適用
-	if (!((battle_config.mob_ghostring_fix == 1) && 
-		(battle_get_elem_type(target) == 8) && 
+	if (!((battle_config.mob_ghostring_fix == 1) &&
+		(battle_get_elem_type(target) == 8) &&
 		(target->type==BL_PC))) // [MouseJstr]
 		if(skill_num != 0 || s_ele != 0 || !battle_config.mob_attack_attr_none)
 			damage=battle_attr_fix(damage, s_ele, battle_get_element(target) );
@@ -3506,7 +3557,7 @@ static struct Damage battle_calc_pc_weapon_attack(
 /*					int mdef1=battle_get_mdef(target);
 					int mdef2=battle_get_mdef2(target);
 					int imdef_flag=0;
-						
+
 					damage = ((damage * 5) + (skill_lv * battle_get_int(src) * 5) + rand()%500 + 500) /2;
 					damage2 = ((damage2 * 5) + (skill_lv * battle_get_int(src) * 5) + rand()%500 + 500) /2;
 					damage3 = damage;
@@ -3520,7 +3571,7 @@ static struct Damage battle_calc_pc_weapon_attack(
 
 					// calculate magic part of damage
 					damage3 = skill_lv * battle_get_int(src) * 5;
-					
+
 					// ignores magic defense now [Celest]
 					/*if(sd->ignore_mdef_ele & (1<<t_ele) || sd->ignore_mdef_race & (1<<t_race))
 						imdef_flag = 1;
@@ -3540,7 +3591,7 @@ static struct Damage battle_calc_pc_weapon_attack(
 							damage3 = (damage3*(100-mdef1))/100 - mdef2;
 						}
 					}
-	
+
 					if(damage3<1)
 						damage3=1;
 
@@ -3688,7 +3739,7 @@ static struct Damage battle_calc_pc_weapon_attack(
 			hitrate -= 50;
 		if (t_sc_data[SC_SLEEP].timer!=-1 ||	// 睡眠は必中
 			t_sc_data[SC_STAN].timer!=-1 ||		// スタンは必中
-			t_sc_data[SC_FREEZE].timer!=-1 || 
+			t_sc_data[SC_FREEZE].timer!=-1 ||
 			(t_sc_data[SC_STONE].timer!=-1 && t_sc_data[SC_STONE].val2==0))	// 凍結は必中
 			hitrate = 1000000;
 	}
@@ -3876,7 +3927,7 @@ static struct Damage battle_calc_pc_weapon_attack(
 		damage = damage2;
 		damage2 = 0;
 	}
-	
+
 	// 右手、左手修練の適用
 	if(sd->status.weapon > 16) {// 二刀流か?
 		int dmg = damage, dmg2 = damage2;
@@ -4258,7 +4309,7 @@ struct Damage battle_calc_magic_attack(
 			} else if (target->type == BL_PC) {
 				damage = ((struct map_session_data *)target)->status.sp * 2;
 				matk_flag = 0; // don't consider matk and matk2
-			}				
+			}
 			break;
 		}
 	}
@@ -4554,6 +4605,7 @@ struct Damage battle_calc_attack(	int attack_type,
 	default:
 		if(battle_config.error_log)
 			printf("battle_calc_attack: unknwon attack type ! %d\n",attack_type);
+		memset(&d,0,sizeof(d));
 		break;
 	}
 	return d;
@@ -4596,7 +4648,7 @@ int battle_weapon_attack( struct block_list *src,struct block_list *target,
 	}
 
 	if(battle_check_target(src,target,BCT_ENEMY) <= 0 &&
-				!battle_check_range(src,target,0))
+		!battle_check_range(src,target,0))
 		return 0;	// 攻撃対象外
 
 	race = battle_get_race(target);
@@ -4810,8 +4862,8 @@ int battle_weapon_attack( struct block_list *src,struct block_list *target,
 				--t_sc_data[SC_POISONREACT].val2;
 			}
 			if (t_sc_data[SC_POISONREACT].val2<=0)
- 				skill_status_change_end(target,SC_POISONREACT,-1);            
-			}         
+ 				skill_status_change_end(target,SC_POISONREACT,-1);
+			}
 		}
 	if (t_sc_data && t_sc_data[SC_BLADESTOP_WAIT].timer != -1 &&
 			!(battle_get_mode(src)&0x20)) { // ボスには無効
@@ -4911,7 +4963,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
 			return -1;
 		if(ss->prev == NULL)
 			return -1;
-		if(inf2&0x80 && 
+		if(inf2&0x80 &&
                    (map[src->m].flag.pvp || pc_iskiller((struct map_session_data *)src, (struct map_session_data *)target)) &&  // [MouseJstr]
                    !(target->type == BL_PC && pc_isinvisible((struct map_session_data *)target)))
 			return 0;
@@ -5037,7 +5089,7 @@ int battle_check_range(struct block_list *src,struct block_list *bl,int range)
 	int dx,dy;
 	struct walkpath_data wpd;
 	int arange;
-	
+
 	nullpo_retr(0, src);
 	nullpo_retr(0, bl);
 
@@ -5182,7 +5234,7 @@ static const struct {
 	{ "item_slots_override_grffile",       &battle_config.item_slots_override_grffile},	// [Celest]
 	{ "indoors_override_grffile",          &battle_config.indoors_override_grffile},	// [Celest]
 	{ "skill_sp_override_grffile",         &battle_config.skill_sp_override_grffile},	// [Celest]
-	{ "cardillust_read_grffile",           &battle_config.cardillust_read_grffile},	// [Celest]	
+	{ "cardillust_read_grffile",           &battle_config.cardillust_read_grffile},	// [Celest]
 	{ "arrow_decrement",                   &battle_config.arrow_decrement			},
 	{ "max_aspd",                          &battle_config.max_aspd					},
 	{ "max_hp",                            &battle_config.max_hp					},
@@ -5329,10 +5381,10 @@ static const struct {
 	{ "allow_atcommand_when_mute",			&battle_config.allow_atcommand_when_mute}, // [celest]
 	{ "finding_ore_rate",       &battle_config.finding_ore_rate}, // [celest]
 	{ "exp_calc_type",          &battle_config.exp_calc_type}, // [celest]
-	{ "double_login_system",    &battle_config.double_login_system}, // [celest]
+	{ "min_skill_delay_limit",    &battle_config.min_skill_delay_limit}, // [celest]
 
 //SQL-only options start
-#ifndef TXT_ONLY 
+#ifndef TXT_ONLY
 	{ "mail_system",		&battle_config.mail_system	}, // added by [Valaris]
 //SQL-only options end
 #endif
@@ -5442,7 +5494,7 @@ void battle_set_defaults() {
 	battle_config.item_slots_override_grffile=0;	// [Celest]
 	battle_config.indoors_override_grffile=0;	// [Celest]
 	battle_config.skill_sp_override_grffile=0;	// [Celest]
-	battle_config.cardillust_read_grffile=0;	// [Celest]	
+	battle_config.cardillust_read_grffile=0;	// [Celest]
 	battle_config.arrow_decrement=1;
 	battle_config.max_aspd = 199;
 	battle_config.max_hp = 32500;
@@ -5590,10 +5642,10 @@ void battle_set_defaults() {
 	battle_config.castrate_dex_scale = 150;
 	battle_config.area_size = 14;
 	battle_config.exp_calc_type = 1;
-	battle_config.double_login_system = 0;
+	battle_config.min_skill_delay_limit = 100;
 
 //SQL-only options start
-#ifndef TXT_ONLY 
+#ifndef TXT_ONLY
 	battle_config.mail_system = 0;
 //SQL-only options end
 #endif
@@ -5710,13 +5762,13 @@ void battle_validate_conf() {
 	// at least 1 client must be accepted
 	if ((battle_config.packet_ver_flag & 127) == 0) // added by [Yor]
 		battle_config.packet_ver_flag = 127; // accept all clients
-	
+
 	if (battle_config.night_darkness_level > 10) // Celest
 		battle_config.night_darkness_level = 10;
 
 	if (battle_config.skill_range_leniency < 0) // Celest
 		battle_config.skill_range_leniency = 0;
-	
+
 	if (battle_config.motd_type < 0)
 		battle_config.motd_type = 0;
 	else if (battle_config.motd_type > 1)
@@ -5728,22 +5780,21 @@ void battle_validate_conf() {
 	if (battle_config.vending_max_value > 10000000 || battle_config.vending_max_value<=0) // Lupus & Kobra_k88
 		battle_config.vending_max_value = 10000000;
 
-	if (battle_config.double_login_system < 0)
-		battle_config.double_login_system = 0;
-
+	if (battle_config.min_skill_delay_limit < 10)
+		battle_config.min_skill_delay_limit = 10;	// minimum delay of 10ms
 }
 
 /*==========================================
  * 設定ファイルを読み込む
  *------------------------------------------
  */
-int battle_config_read(const char *cfgName) 
+int battle_config_read(const char *cfgName)
 {
 	char line[1024], w1[1024], w2[1024];
 	FILE *fp;
 	static int count = 0;
 
-	if ((count++) == 0) 
+	if ((count++) == 0)
 		battle_set_defaults();
 
 	fp = fopen(cfgName,"r");

+ 4 - 3
src/map/battle.h

@@ -115,6 +115,7 @@ enum {
 	BCT_NOPARTY	=0x50000,
 	BCT_ALL		=0x20000,
 	BCT_NOONE	=0x60000,
+	BCT_SELF	=0x60000,
 };
 
 int battle_check_undead(int race,int element);
@@ -291,7 +292,7 @@ extern struct Battle_Config {
 	int prevent_logout;	// Added by RoVeRT
 
 	int alchemist_summon_reward;	// [Valaris]
-	int maximum_level;
+	unsigned int maximum_level;
 	int drops_by_luk;
 	int monsters_ignore_gm;
 	int equipment_breaking;
@@ -348,7 +349,7 @@ extern struct Battle_Config {
 
 	int zeny_from_mobs; // [Valaris]
 	int mobs_level_up; // [Valaris]
-	int pk_min_level; // [celest]
+	unsigned int pk_min_level; // [celest]
 	int skill_steal_type; // [celest]
 	int skill_steal_rate; // [celest]
 	int night_darkness_level; // [celest]
@@ -357,7 +358,7 @@ extern struct Battle_Config {
 	int allow_atcommand_when_mute; // [celest]
 	int finding_ore_rate; // orn
 	int exp_calc_type;
-	int double_login_system;
+	int min_skill_delay_limit;
 
 #ifndef TXT_ONLY /* SQL-only options */
 	int mail_system; // [Valaris]

+ 2 - 2
src/map/charcommand.c

@@ -1063,8 +1063,8 @@ int charcommand_item(
 					if (pet_id >= 0) {
 						sd->catch_target_class = pet_db[pet_id].class_;
 						intif_create_pet(sd->status.account_id, sd->status.char_id,
-						                 pet_db[pet_id].class_, mob_db[pet_db[pet_id].class_].lv,
-						                 pet_db[pet_id].EggID, 0, pet_db[pet_id].intimate,
+						                 (short)pet_db[pet_id].class_, (short)mob_db[pet_db[pet_id].class_].lv,
+						                 (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
 						                 100, 0, 1, pet_db[pet_id].jname);
 					// if not pet egg
 					} else {

+ 3 - 3
src/map/chat.c

@@ -49,7 +49,7 @@ int chat_createchat(struct map_session_data *sd,int limit,int pub,char* pass,cha
 	cd->bl.id = map_addobject(&cd->bl);	
 	if(cd->bl.id==0){
 		clif_createchat(sd,1);
-		free(cd);
+		aFree(cd);
 		return 0;
 	}
 	pc_setchatid(sd,cd->bl.id);
@@ -82,7 +82,7 @@ int chat_joinchat(struct map_session_data *sd,int chatid,char* pass)
 		clif_joinchatfail(sd,1);
 		return 0;
 	}
-	if(chatid == sd->chatID) //Double Chat fix by Alex14, thx CHaNGeTe 
+	if(chatid == (int)sd->chatID) //Double Chat fix by Alex14, thx CHaNGeTe 
 	{
 		clif_joinchatfail(sd,1);
 		return 0;
@@ -290,7 +290,7 @@ int chat_createnpcchat(struct npc_data *nd,int limit,int pub,int trigger,char* t
 
 	cd->bl.id = map_addobject(&cd->bl);	
 	if(cd->bl.id==0){
-		free(cd);
+		aFree(cd);
 		return 0;
 	}
 	nd->chat_id=cd->bl.id;

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 203 - 157
src/map/clif.c


+ 10 - 4
src/map/clif.h

@@ -16,7 +16,6 @@ typedef unsigned int in_addr_t;
 #define MAX_PACKET_DB		0x224
 #define MAX_PACKET_VER		17
 
-extern int packet_db_ver;
 struct packet_db {
 	short len;
 	void (*func)();
@@ -24,6 +23,13 @@ struct packet_db {
 };
 extern struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
 
+extern struct Clif_Config {
+	int enable_packet_db;
+	int packet_db_ver;
+	int prefer_packet_db;
+	int connect_cmd;
+} clif_config;
+
 void clif_setip(char*);
 void clif_setport(int);
 
@@ -137,8 +143,8 @@ int clif_petinsight(struct block_list *bl,va_list ap);
 int clif_npcoutsight(struct block_list *bl,va_list ap);
 int clif_npcinsight(struct block_list *bl,va_list ap);
 
-int clif_class_change(struct block_list *bl,int class,int type);
-int clif_mob_class_change(struct mob_data *md,int class);
+int clif_class_change(struct block_list *bl,int class_,int type);
+int clif_mob_class_change(struct mob_data *md,int class_);
 int clif_mob_equip(struct mob_data *md,int nameid); // [Valaris]
 
 int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range);
@@ -177,7 +183,7 @@ int clif_autospell(struct map_session_data *sd,int skilllv);
 int clif_devotion(struct map_session_data *sd,int target);
 int clif_spiritball(struct map_session_data *sd);
 int clif_combo_delay(struct block_list *src,int wait);
-int clif_bladestop(struct block_list *src,struct block_list *dst,int bool);
+int clif_bladestop(struct block_list *src,struct block_list *dst,int bool_);
 int clif_changemapcell(int m,int x,int y,int cell_type,int type);
 
 int clif_status_change(struct block_list *bl,int type,int flag);

+ 18 - 18
src/map/guild.c

@@ -284,7 +284,7 @@ int guild_payexp_timer_sub(void *key,void *data,va_list ap)
 	c->exp=0;
 
 	dellist[(*delp)++]=dataid;
-	free(c);
+	aFree(c);
 	return 0;
 }
 int guild_payexp_timer(int tid,unsigned int tick,int id,int data)
@@ -476,7 +476,7 @@ int guild_recv_info(struct guild *sg)
 	// イベントの発生
 	if( (ev=numdb_search(guild_infoevent_db,sg->guild_id))!=NULL ){
 		numdb_erase(guild_infoevent_db,sg->guild_id);
-		for(;ev;ev2=ev->next,free(ev),ev=ev2){
+		for(;ev;ev2=ev->next,aFree(ev),ev=ev2){
 			npc_event_do(ev->name);
 		}
 	}
@@ -750,7 +750,7 @@ int guild_send_memberinfoshort(struct map_session_data *sd,int online)
 	return 0;
 }
 // ギルドメンバのオンライン状態/Lv更新通知
-int guild_recv_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class)
+int guild_recv_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class_)
 {
 	int i,alv,c,idx=0,om=0,oldonline=-1;
 	struct guild *g=guild_search(guild_id);
@@ -762,7 +762,7 @@ int guild_recv_memberinfoshort(int guild_id,int account_id,int char_id,int onlin
 			oldonline=m->online;
 			m->online=online;
 			m->lv=lv;
-			m->class_=class;
+			m->class_=class_;
 			idx=i;
 		}
 		if(m->account_id>0){
@@ -938,7 +938,7 @@ int guild_payexp(struct map_session_data *sd,int exp)
 		return 0;
 
 	if( (c=numdb_search(guild_expcache_db,sd->status.char_id))==NULL ){
-		c=(struct guild_expcache *)aCalloc(1,sizeof(struct guild_expcache));
+		c=(struct guild_expcache *)aCallocA(1,sizeof(struct guild_expcache));
 		c->guild_id=sd->status.guild_id;
 		c->account_id=sd->status.account_id;
 		c->char_id=sd->status.char_id;
@@ -960,9 +960,9 @@ int guild_getexp(struct map_session_data *sd,int exp)
 
 	if(sd->status.guild_id==0 || (g=guild_search(sd->status.guild_id))==NULL )
 		return 0;
-	
+
 	if( (c=numdb_search(guild_expcache_db,sd->status.char_id))==NULL ){
-		c=(struct guild_expcache *)aCalloc(1,sizeof(struct guild_expcache));
+		c=(struct guild_expcache *)aCallocA(1,sizeof(struct guild_expcache));
 		c->guild_id=sd->status.guild_id;
 		c->account_id=sd->status.account_id;
 		c->char_id=sd->status.char_id;
@@ -1191,7 +1191,7 @@ int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id
 	const char *guild_name[2];
 	struct map_session_data *sd[2];
 	int j,i;
-	
+
 	guild_id[0] = guild_id1;
 	guild_id[1] = guild_id2;
 	guild_name[0] = name1;
@@ -1300,7 +1300,7 @@ int guild_broken(int guild_id,int flag)
 	numdb_foreach(guild_db,guild_broken_sub,guild_id);
 	numdb_erase(guild_db,guild_id);
 	guild_storage_delete(guild_id);
-	free(g);
+	aFree(g);
 	return 0;
 }
 
@@ -1396,7 +1396,7 @@ int guild_castledataloadack(int castle_id,int index,int value)
 	}
 	if( (ev=numdb_search(guild_castleinfoevent_db,code))!=NULL ){
 		numdb_erase(guild_castleinfoevent_db,code);
-		for(;ev;ev2=ev->next,free(ev),ev=ev2){
+		for(;ev;ev2=ev->next,aFree(ev),ev=ev2){
 			npc_event_do(ev->name);
 		}
 	}
@@ -1500,7 +1500,7 @@ int guild_agit_end(void)
 int guild_gvg_eliminate_timer(int tid,unsigned int tick,int id,int data)
 {	// Run One NPC_Event[OnAgitEliminate]
 	size_t len = strlen((const char*)data);
-	char *evname=(char*)aCalloc(len + 4,sizeof(char));
+	char *evname=(char*)aCallocA(len + 4,sizeof(char));
 	int c=0;
 
 	if(!agit_flag) return 0;	// Agit already End
@@ -1517,7 +1517,7 @@ int guild_agit_break(struct mob_data *md)
 
 	nullpo_retr(0, md);
 
-	evname=(char *)aCalloc(strlen(md->npc_event) + 1, sizeof(char));
+	evname=(char *)aCallocA(strlen(md->npc_event) + 1, sizeof(char));
 
 	strcpy(evname,md->npc_event);
 // Now By User to Run [OnAgitBreak] NPC Event...
@@ -1539,7 +1539,7 @@ int guild_checkcastles(struct guild *g) {
 	for(i=0;i<MAX_GUILDCASTLE;i++){
 		gc=guild_castle_search(i);
 		cas_id=gc->guild_id;
-		if(g->guild_id==cas_id) 
+		if(g->guild_id==cas_id)
 			nb_cas=nb_cas+1;
 		} //end for
 	return nb_cas;
@@ -1570,12 +1570,12 @@ int guild_isallied(struct guild *g, struct guild_castle *gc)
 
 	return 0;
 }
-  
+
 static int guild_db_final(void *key,void *data,va_list ap)
 {
 	struct guild *g=data;
 
-	free(g);
+	aFree(g);
 
 	return 0;
 }
@@ -1583,7 +1583,7 @@ static int castle_db_final(void *key,void *data,va_list ap)
 {
 	struct guild_castle *gc=data;
 
-	free(gc);
+	aFree(gc);
 
 	return 0;
 }
@@ -1591,7 +1591,7 @@ static int guild_expcache_db_final(void *key,void *data,va_list ap)
 {
 	struct guild_expcache *c=data;
 
-	free(c);
+	aFree(c);
 
 	return 0;
 }
@@ -1599,7 +1599,7 @@ static int guild_infoevent_db_final(void *key,void *data,va_list ap)
 {
 	struct eventlist *ev=data;
 
-	free(ev);
+	aFree(ev);
 
 	return 0;
 }

+ 1 - 1
src/map/guild.h

@@ -56,7 +56,7 @@ int guild_delalliance(struct map_session_data *sd,int guild_id,int flag);
 int guild_opposition(struct map_session_data *sd,int char_id);
 
 int guild_send_memberinfoshort(struct map_session_data *sd,int online);
-int guild_recv_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class);
+int guild_recv_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class_);
 int guild_change_memberposition(int guild_id,int account_id,int char_id,int idx);
 int guild_memberposition_changed(struct guild *g,int idx,int pos);
 int guild_change_position(struct map_session_data *sd,int idx,

+ 5 - 5
src/map/intif.c

@@ -457,7 +457,7 @@ int intif_guild_leave(int guild_id,int account_id,int char_id,int flag,const cha
 }
 // ギルドメンバのオンライン状況/Lv更新要求
 int intif_guild_memberinfoshort(int guild_id,
-	int account_id,int char_id,int online,int lv,int class)
+	int account_id,int char_id,int online,int lv,int class_)
 {
 	if (CheckForCharServer())
 		return 0;
@@ -467,7 +467,7 @@ int intif_guild_memberinfoshort(int guild_id,
 	WFIFOL(inter_fd,10) = char_id;
 	WFIFOB(inter_fd,14) = online;
 	WFIFOW(inter_fd,15) = lv;
-	WFIFOW(inter_fd,17) = class;
+	WFIFOW(inter_fd,17) = class_;
 	WFIFOSET(inter_fd,19);
 	return 0;
 }
@@ -640,7 +640,7 @@ int intif_parse_WisMessage(int fd) { // rewritten by [Yor]
 
 //	if(battle_config.etc_log)
 //		printf("intif_parse_wismessage: %d %s %s %s\n",id,RFIFOP(fd,6),RFIFOP(fd,30),RFIFOP(fd,54) );
-	
+
 	sd=map_nick2sd(RFIFOP(fd,32));	// 送信先を探す
 	if(sd!=NULL && strcmp(sd->status.name, RFIFOP(fd,32)) == 0){
 /*
@@ -698,7 +698,7 @@ int mapif_parse_WisToGM(int fd) { // 0x3003/0x3803 <packet_len>.w <wispname>.24B
 	struct map_session_data *pl_sd;
 	char Wisp_name[24];
         char mbuf[255];
-	char *message = ((RFIFOW(fd,2) - 30) >= sizeof(mbuf)) ? (char *) aMalloc((RFIFOW(fd,2) - 30)) : mbuf;
+	char *message = ((RFIFOW(fd,2) - 30) >= sizeof(mbuf)) ? (char *) aMallocA((RFIFOW(fd,2) - 30)) : mbuf;
 
 	min_gm_level = (int)RFIFOW(fd,28);
 	memcpy(Wisp_name, RFIFOP(fd,4), 24);
@@ -712,7 +712,7 @@ int mapif_parse_WisToGM(int fd) { // 0x3003/0x3803 <packet_len>.w <wispname>.24B
 				clif_wis_message(i, Wisp_name, message, strlen(message) + 1);
 
         if (message != mbuf)
-            free(message);
+            aFree(message);
 
 	return 0;
 }

+ 1 - 1
src/map/intif.h

@@ -33,7 +33,7 @@ int intif_guild_create(const char *name, const struct guild_member *master);
 int intif_guild_request_info(int guild_id);
 int intif_guild_addmember(int guild_id, struct guild_member *m);
 int intif_guild_leave(int guild_id, int account_id, int char_id, int flag, const char *mes);
-int intif_guild_memberinfoshort(int guild_id, int account_id, int char_id, int online, int lv, int class);
+int intif_guild_memberinfoshort(int guild_id, int account_id, int char_id, int online, int lv, int class_);
 int intif_guild_break(int guild_id);
 int intif_guild_message(int guild_id, int account_id, char *mes, int len);
 int intif_guild_checkconflict(int guild_id, int account_id, int char_id);

+ 7 - 7
src/map/itemdb.c

@@ -530,7 +530,7 @@ static int itemdb_read_itemnametable(void)
 		if(!p) break;
 		p++;
 	}
-	free(buf);
+	aFree(buf);
 	sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\idnum2itemdisplaynametable.txt");
 	ShowStatus(tmp_output);
 
@@ -566,7 +566,7 @@ static int itemdb_read_cardillustnametable(void)
 		if(!p) break;
 		p++;
 	}
-	free(buf);
+	aFree(buf);
 	sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\num2cardillustnametable.txt");
 	ShowStatus(tmp_output);
 
@@ -604,7 +604,7 @@ static int itemdb_read_itemslottable(void)
 		if(!p) break;
 		p++;
 	}
-	free(buf);
+	aFree(buf);
 	sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\itemslottable.txt");
 	ShowStatus(tmp_output);
 
@@ -636,7 +636,7 @@ static int itemdb_read_itemslotcounttable(void)
 		if(!p) break;
 		p++;
 	}
-	free(buf);
+	aFree(buf);
 	sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\itemslotcounttable.txt");
 	ShowStatus(tmp_output);
 
@@ -896,10 +896,10 @@ static int itemdb_final(void *key,void *data,va_list ap)
 	nullpo_retr(0, id=data);
 
 	if(id->use_script)
-		free(id->use_script);
+		aFree(id->use_script);
 	if(id->equip_script)
-		free(id->equip_script);
-	free(id);
+		aFree(id->equip_script);
+	aFree(id);
 
 	return 0;
 }

+ 28 - 28
src/map/mail.c

@@ -30,12 +30,12 @@ extern char msg_table[1000][256]; // Server messages (0-499 reserved for GM comm
 
 int mail_check(struct map_session_data *sd,int type)
 {
-	int i=0,new=0,priority=0;
+	int i=0,new_=0,priority=0;
 	char message[50];
 
 	if(sd==NULL)
 		return 0;
-	
+
 	sprintf(tmp_msql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`read_flag`,`priority`,`check_flag` FROM `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id`", mail_db, sd->status.account_id);
 
 	if (mysql_query(&mail_handle, tmp_msql)) {
@@ -64,7 +64,7 @@ int mail_check(struct map_session_data *sd,int type)
 				}
 
 				if(!atoi(mail_row[3])) {
-					new++;
+					new_++;
 					if(atoi(mail_row[4]))
 						priority++;
 					if(type==2 || type==3) {
@@ -88,28 +88,28 @@ int mail_check(struct map_session_data *sd,int type)
 						sprintf(message, msg_table[513], i, mail_row[2]);
 						clif_displaymessage(sd->fd, jstrescape(message));
 					}
-				
+
 	        }
-    	
+
 		mysql_free_result(mail_res);
-	
+
 	} else {
         	printf("MySQL error (storing query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
 		return 0;
     	}
 
-	if(i>0 && new>0 && type==1) {
-		//sprintf(message, "You have %d new messages.", new);
-		sprintf(message, msg_table[514], new);
+	if(i>0 && new_>0 && type==1) {
+		//sprintf(message, "You have %d new messages.", new_);
+		sprintf(message, msg_table[514], new_);
 
 		clif_displaymessage(sd->fd, jstrescape(message));
 	}
-	if(i>0 && new>0 && priority>0 && type==1) {
+	if(i>0 && new_>0 && priority>0 && type==1) {
 		//sprintf(message, "You have %d unread priority messages.", priority);
 		sprintf(message, msg_table[515], priority);
 		clif_displaymessage(sd->fd, jstrescape(message));
 	}
-	if(!new) {
+	if(!new_) {
 		//clif_displaymessage(sd->fd, "You have no new messages.");
 		clif_displaymessage(sd->fd, msg_table[516]);
 	}
@@ -124,7 +124,7 @@ int mail_read(struct map_session_data *sd, int message_id)
 
 	if(sd==NULL)
 		return 0;
-	
+
 	sprintf(tmp_msql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`message`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id` LIMIT %d, 1",mail_db,sd->status.account_id,message_id-1);
 
 	if (mysql_query(&mail_handle, tmp_msql)) {
@@ -162,9 +162,9 @@ int mail_read(struct map_session_data *sd, int message_id)
 				printf("DB server Error (update Read `%s`)- %s\n", mail_db, mysql_error(&mail_handle) );
 		        }
 		}
-	
+
 		mysql_free_result(mail_res);
-	
+
 	} else {
         	printf("MySQL error (storing query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
 		return 0;
@@ -177,7 +177,7 @@ int mail_delete(struct map_session_data *sd, int message_id)
 {
 	if(sd==NULL)
 		return 0;
-	
+
 	sprintf(tmp_msql,"SELECT `message_id`,`to_account_id`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id` LIMIT %d, 1",mail_db,sd->status.account_id,message_id-1);
 
 	if (mysql_query(&mail_handle, tmp_msql)) {
@@ -217,9 +217,9 @@ int mail_delete(struct map_session_data *sd, int message_id)
 			//else clif_displaymessage(sd->fd,"Message deleted.");
 			else clif_displaymessage(sd->fd,msg_table[521]);
 		}
-	
+
 		mysql_free_result(mail_res);
-	
+
 	} else {
         	printf("MySQL error (delete query result for %s): %s\n", mail_db, mysql_error(&mail_handle));
 		return 0;
@@ -232,7 +232,7 @@ int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
 {
 	if(sd==NULL)
 		return 0;
-		
+
 	if(pc_isGM(sd) < 80 && sd->mail_counter > 0) {
 		//clif_displaymessage(sd->fd,"You must wait 10 minutes before sending another message");
 		clif_displaymessage(sd->fd,msg_table[522]);
@@ -254,8 +254,8 @@ int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
 	if (mysql_query(&mail_handle, tmp_msql)) {
 		printf("Database server error (executing query for %s): %s\n", char_db, mysql_error(&mail_handle));
 		return 0;
-   	}	
-	
+   	}
+
    	mail_res = mysql_store_result(&mail_handle);
 	if(mail_res) {
 	        if (mysql_num_rows(mail_res) == 0) {
@@ -268,7 +268,7 @@ int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
 	        while ((mail_row = mysql_fetch_row(mail_res))) {
 			if(strcmp(name,"*")==0) {
 				sprintf(tmp_msql, "INSERT DELAYED INTO `%s` (`to_account_id`,`from_account_id`,`from_char_name`,`message`,`priority`)"
-					" VALUES ('%d', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), sd->status.account_id, sd->status.name, jstrescape(message), flag);			
+					" VALUES ('%d', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), sd->status.account_id, sd->status.name, jstrescape(message), flag);
 			}
 			else {
 				sprintf(tmp_msql, "INSERT DELAYED INTO `%s` (`to_account_id`,`to_char_name`,`from_account_id`,`from_char_name`,`message`,`priority`)"
@@ -276,7 +276,7 @@ int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
 				if(pc_isGM(sd) < 80)
 					sd->mail_counter=5;
 			}
-	
+
 			if(mysql_query(&mail_handle, tmp_msql) ) {
 				mysql_free_result(mail_res);
 				printf("DB server Error (insert `mail_db`)- %s\n", mysql_error(&mail_handle) );
@@ -295,18 +295,18 @@ int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
 int mail_check_timer(int tid,unsigned int tick,int id,int data)
 {
 	struct map_session_data *sd = NULL;
-	int i;		
+	int i;
 
 	if(mail_timer != tid)
 		return 0;
 
 	sprintf(tmp_msql,"SELECT DISTINCT `to_account_id` FROM `%s` WHERE `read_flag` = '0' AND `check_flag` = '0'", mail_db);
-	
+
 	if (mysql_query(&mail_handle, tmp_msql)) {
 		printf("Database server error (executing query for %s): %s\n", char_db, mysql_error(&mail_handle));
 		mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0);
 		return 0;
-   	}	
+   	}
 
 	mail_res = mysql_store_result(&mail_handle);
 
@@ -324,8 +324,8 @@ int mail_check_timer(int tid,unsigned int tick,int id,int data)
 					if(pc_isGM(sd) < 80 && sd->mail_counter > 0)
 						sd->mail_counter--;
 					if(sd->status.account_id==atoi(mail_row[0]))
-						//clif_displaymessage(sd->fd, "You have new mail.");						
-						clif_displaymessage(sd->fd, msg_table[526]);						
+						//clif_displaymessage(sd->fd, "You have new mail.");
+						clif_displaymessage(sd->fd, msg_table[526]);
 				}
 			}
 		}
@@ -341,7 +341,7 @@ int mail_check_timer(int tid,unsigned int tick,int id,int data)
 }
 
 int do_init_mail(void)
-{	
+{
 	add_timer_func_list(mail_check_timer,"mail_check_timer");
 	mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0);
 	return 0;

+ 101 - 94
src/map/map.c

@@ -193,7 +193,7 @@ int map_getusers(void) {
 int map_freeblock( void *bl )
 {
 	if(block_free_lock==0){
-		free(bl);
+		aFree(bl);
 		bl = NULL;
 	}
 	else{
@@ -229,7 +229,7 @@ int map_freeblock_unlock(void) {
 //				printf("map_freeblock_unlock: free %d object\n",block_free_count);
 //		}
 		for(i=0;i<block_free_count;i++){
-			free(block_free[i]);
+			aFree(block_free[i]);
 			block_free[i] = NULL;
 		}
 		block_free_count=0;
@@ -847,7 +847,7 @@ int map_addflooritem(struct item *item_data,int amount,int m,int x,int y,struct
 
 	fitem->bl.id = map_addobject(&fitem->bl);
 	if(fitem->bl.id==0){
-		free(fitem);
+		aFree(fitem);
 		return 0;
 	}
 
@@ -894,9 +894,9 @@ void map_addchariddb(int charid, char *name) {
 	struct charid2nick *p=NULL;
 	int req=0;
 
-	p=numdb_search(charid_db,charid);
+	p = (struct charid2nick*)numdb_search(charid_db,charid);
 	if(p==NULL){	// デ?タベ?スにない
-		p = (struct charid2nick *)aCalloc(1,sizeof(struct charid2nick));
+		p = (struct charid2nick *)aCallocA(1,sizeof(struct charid2nick));
 		p->req_id=0;
 	}else
 		numdb_erase(charid_db,charid);
@@ -921,7 +921,7 @@ int map_reqchariddb(struct map_session_data * sd,int charid) {
 
 	nullpo_retr(0, sd);
 
-	p=numdb_search(charid_db,charid);
+	p = (struct charid2nick*)numdb_search(charid_db,charid);
 	if(p!=NULL)	// デ?タベ?スにすでにある
 		return 0;
 	p = (struct charid2nick *)aCalloc(1,sizeof(struct charid2nick));
@@ -1005,7 +1005,7 @@ int map_quit(struct map_session_data *sd) {
 	// check if we've been authenticated [celest]
 	if (sd->state.auth)
 		skill_castcancel(&sd->bl,0);	// 詠唱を中?する
-	
+
 	skill_stop_dancing(&sd->bl,1);// ダンス/演奏中?
 
 	if(sd->sc_data && sd->sc_data[SC_BERSERK].timer!=-1) //バ?サ?ク中の終了はHPを100に
@@ -1052,7 +1052,7 @@ int map_quit(struct map_session_data *sd) {
 	storage_storage_save(sd);
 
 	if( sd->npc_stackbuf && sd->npc_stackbuf != NULL) {
-		free( sd->npc_stackbuf );
+		aFree( sd->npc_stackbuf );
 		sd->npc_stackbuf = NULL;
 	}
 
@@ -1092,7 +1092,7 @@ struct map_session_data * map_id2sd(int id) {
 	struct map_session_data *sd=NULL;
 
 	for(i = 0; i < fd_max; i++)
-		if (session[i] && (sd = session[i]->session_data) && sd->bl.id == id)
+		if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) && sd->bl.id == id)
 			return sd;
 
 	return NULL;
@@ -1103,7 +1103,7 @@ struct map_session_data * map_id2sd(int id) {
  *------------------------------------------
  */
 char * map_charid2nick(int id) {
-	struct charid2nick *p=numdb_search(charid_db,id);
+	struct charid2nick *p = (struct charid2nick*)numdb_search(charid_db,id);
 
 	if(p==NULL)
 		return NULL;
@@ -1130,7 +1130,7 @@ struct map_session_data * map_nick2sd(char *nick) {
     nicklen = strlen(nick);
 
 	for (i = 0; i < fd_max; i++) {
-		if (session[i] && (pl_sd = session[i]->session_data) && pl_sd->state.auth)
+		if (session[i] && (pl_sd = (struct map_session_data*)session[i]->session_data) && pl_sd->state.auth)
 			// Without case sensitive check (increase the number of similar character names found)
 			if (strnicmp(pl_sd->status.name, nick, nicklen) == 0) {
 				// Strict comparison (if found, we finish the function immediatly with correct value)
@@ -1160,7 +1160,7 @@ struct block_list * map_id2bl(int id)
 	if(id<sizeof(object)/sizeof(object[0]))
 		bl = object[id];
 	else
-		bl = numdb_search(id_db,id);
+		bl = (struct block_list*)numdb_search(id_db,id);
 
 	return bl;
 }
@@ -1217,10 +1217,10 @@ void map_removenpc(void) {
                 map_delblock(&map[m].npc[i]->bl);
                 numdb_erase(id_db,map[m].npc[i]->bl.id);
                 if(map[m].npc[i]->bl.subtype==SCRIPT) {
-//                    free(map[m].npc[i]->u.scr.script);
-//                    free(map[m].npc[i]->u.scr.label_list);
+//                    aFree(map[m].npc[i]->u.scr.script);
+//                    aFree(map[m].npc[i]->u.scr.label_list);
                 }
-                free(map[m].npc[i]);
+                aFree(map[m].npc[i]);
                 map[m].npc[i] = NULL;
                 n++;
             }
@@ -1238,7 +1238,7 @@ void map_removenpc(void) {
 int map_mapname2mapid(char *name) {
 	struct map_data *md=NULL;
 
-	md=strdb_search(map_db,name);
+	md = (struct map_data*)strdb_search(map_db,name);
 
 	#ifdef USE_AFM
 		// If we can't find the .gat map try .afm instead [celest]
@@ -1246,7 +1246,7 @@ int map_mapname2mapid(char *name) {
 			char afm_name[16] = "";
 			strncpy(afm_name, name, strlen(name) - 4);
 			strcat(afm_name, ".afm");
-			md = strdb_search(map_db,afm_name);
+			md = (struct map_data*)strdb_search(map_db,afm_name);
 		}
 	#endif
 
@@ -1262,7 +1262,7 @@ int map_mapname2mapid(char *name) {
 int map_mapname2ipport(char *name,int *ip,int *port) {
 	struct map_data_other_server *mdos=NULL;
 
-	mdos=strdb_search(map_db,name);
+	mdos = (struct map_data_other_server*)strdb_search(map_db,name);
 	if(mdos==NULL || mdos->gat)
 		return -1;
 	*ip=mdos->ip;
@@ -1385,7 +1385,7 @@ int map_getcellp(struct map_data* m,int x,int y,CELL_CHK cellchk)
 		case CELL_CHKTYPE:
 			return m->gat[j];
 		default: return 0;
-	}	
+	}
 	return 0;
 }
 
@@ -1396,7 +1396,7 @@ int map_getcellp(struct map_data* m,int x,int y,CELL_CHK cellchk)
 int map_setcell(int m,int x,int y,CELL_SET cellset)
 {
 	int i,j;
-		
+
 	if(x<0 || x>=map[m].xs || y<0 || y>=map[m].ys)
 		return 0;
 	j=x+y*map[m].xs;
@@ -1431,7 +1431,7 @@ int map_setipport(char *name,unsigned long ip,int port) {
 	struct map_data *md=NULL;
 	struct map_data_other_server *mdos=NULL;
 
-	md=strdb_search(map_db,name);
+	md = (struct map_data*)strdb_search(map_db,name);
 	if(md==NULL){ // not exist -> add new data
 		mdos=(struct map_data_other_server *)aCalloc(1,sizeof(struct map_data_other_server));
 		memcpy(mdos->name,name,24);
@@ -1459,7 +1459,7 @@ int map_setipport(char *name,unsigned long ip,int port) {
  * 水場高さ設定
  *------------------------------------------
  */
-static struct {
+static struct waterlist_ {
 	char mapname[24];
 	int waterheight;
 } *waterlist=NULL;
@@ -1487,7 +1487,7 @@ static void map_readwater(char *watertxt) {
 		return;
 	}
 	if(waterlist==NULL)
-		waterlist=aCalloc(MAX_MAP_PER_SERVER,sizeof(*waterlist));
+		waterlist = (struct waterlist_*)aCallocA(MAX_MAP_PER_SERVER,sizeof(*waterlist));
 	while(fgets(line,1020,fp) && n < MAX_MAP_PER_SERVER){
 		int wh,count;
 		if(line[0] == '/' && line[1] == '/')
@@ -1554,7 +1554,7 @@ static int map_cache_open(char *fn) {
 			map_cache.head.filesize      == ftell(map_cache.fp)
 		) {
 			// キャッシュ読み込み成功
-			map_cache.map = aMalloc(sizeof(struct MAP_CACHE_INFO) * map_cache.head.nmaps);
+			map_cache.map = (struct MAP_CACHE_INFO*)aMallocA(sizeof(struct MAP_CACHE_INFO) * map_cache.head.nmaps);
 			fseek(map_cache.fp,sizeof(struct MAP_CACHE_HEAD),SEEK_SET);
 			fread(map_cache.map,sizeof(struct MAP_CACHE_INFO),map_cache.head.nmaps,map_cache.fp);
 			return 1;
@@ -1567,7 +1567,7 @@ static int map_cache_open(char *fn) {
 	map_cache.fp = fopen(fn,"wb");
 	if(map_cache.fp) {
 		memset(&map_cache.head,0,sizeof(struct MAP_CACHE_HEAD));
-		map_cache.map   = aCalloc(sizeof(struct MAP_CACHE_INFO),MAX_CAHCE_MAX);
+		map_cache.map = (struct MAP_CACHE_INFO*)aCallocA(sizeof(struct MAP_CACHE_INFO),MAX_CAHCE_MAX);
 		map_cache.head.nmaps         = MAX_CAHCE_MAX;
 		map_cache.head.sizeof_header = sizeof(struct MAP_CACHE_HEAD);
 		map_cache.head.sizeof_map    = sizeof(struct MAP_CACHE_INFO);
@@ -1589,7 +1589,7 @@ static void map_cache_close(void) {
 		fwrite(map_cache.map,map_cache.head.nmaps,sizeof(struct MAP_CACHE_INFO),map_cache.fp);
 	}
 	fclose(map_cache.fp);
-	free(map_cache.map);
+	aFree(map_cache.map);
 	map_cache.fp = NULL;
 	return;
 }
@@ -1607,14 +1607,14 @@ int map_cache_read(struct map_data *m) {
 				int size = map_cache.map[i].xs * map_cache.map[i].ys;
 				m->xs = map_cache.map[i].xs;
 				m->ys = map_cache.map[i].ys;
-				m->gat = (unsigned char *)aCalloc(m->xs * m->ys,sizeof(unsigned char));
+				m->gat = (unsigned char *)aCallocA(m->xs * m->ys,sizeof(unsigned char));
 				fseek(map_cache.fp,map_cache.map[i].pos,SEEK_SET);
 				if(fread(m->gat,1,size,map_cache.fp) == size) {
 					// 成功
 					return 1;
 				} else {
 					// なぜかファイル後半が欠けてるので読み直し
-					m->xs = 0; m->ys = 0; m->gat = NULL; free(m->gat);
+					m->xs = 0; m->ys = 0; m->gat = NULL; aFree(m->gat);
 					return 0;
 				}
 			} else if(map_cache.map[i].compressed == 1) {
@@ -1624,14 +1624,14 @@ int map_cache_read(struct map_data *m) {
 				int size_compress = map_cache.map[i].compressed_len;
 				m->xs = map_cache.map[i].xs;
 				m->ys = map_cache.map[i].ys;
-				m->gat = (unsigned char *)aMalloc(m->xs * m->ys * sizeof(unsigned char));
-				buf = (unsigned char*)aMalloc(size_compress);
+				m->gat = (unsigned char *)aMallocA(m->xs * m->ys * sizeof(unsigned char));
+				buf = (unsigned char*)aMallocA(size_compress);
 				fseek(map_cache.fp,map_cache.map[i].pos,SEEK_SET);
 				if(fread(buf,1,size_compress,map_cache.fp) != size_compress) {
 					// なぜかファイル後半が欠けてるので読み直し
 					printf("fread error\n");
 					m->xs = 0; m->ys = 0; m->gat = NULL;
-					free(m->gat); free(buf);
+					aFree(m->gat); aFree(buf);
 					return 0;
 				}
 				dest_len = m->xs * m->ys;
@@ -1639,10 +1639,10 @@ int map_cache_read(struct map_data *m) {
 				if(dest_len != map_cache.map[i].xs * map_cache.map[i].ys) {
 					// 正常に解凍が出来てない
 					m->xs = 0; m->ys = 0; m->gat = NULL;
-					free(m->gat); free(buf);
+					aFree(m->gat); aFree(buf);
 					return 0;
 				}
-				free(buf);
+				aFree(buf);
 				return 1;
 			}
 		}
@@ -1669,7 +1669,7 @@ static int map_cache_write(struct map_data *m) {
 			if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
 				// 圧縮保存
 				// さすがに2倍に膨れる事はないという事で
-				write_buf = aMalloc(m->xs * m->ys * 2);
+				write_buf = (char*)aMallocA(m->xs * m->ys * 2);
 				len_new = m->xs * m->ys * 2;
 				encode_zip(write_buf,&len_new,m->gat,m->xs * m->ys);
 				map_cache.map[i].compressed     = 1;
@@ -1678,7 +1678,7 @@ static int map_cache_write(struct map_data *m) {
 				len_new = m->xs * m->ys;
 				write_buf = m->gat;
 				map_cache.map[i].compressed     = 0;
-				map_cache.map[i].compressed_len = 0;	
+				map_cache.map[i].compressed_len = 0;
 			}
 			if(len_new <= len_old) {
 				// サイズが同じか小さくなったので場所は変わらない
@@ -1696,7 +1696,7 @@ static int map_cache_write(struct map_data *m) {
 			map_cache.map[i].water_height = map_waterheight(m->name);
 			map_cache.dirty = 1;
 			if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
-				free(write_buf);
+				aFree(write_buf);
 			}
 			return 0;
 		}
@@ -1706,7 +1706,7 @@ static int map_cache_write(struct map_data *m) {
 		if(map_cache.map[i].fn[0] == 0) {
 			// 新しい場所に登録
 			if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
-				write_buf = aMalloc(m->xs * m->ys * 2);
+				write_buf = (char*)aMallocA(m->xs * m->ys * 2);
 				len_new = m->xs * m->ys * 2;
 				encode_zip(write_buf,&len_new,m->gat,m->xs * m->ys);
 				map_cache.map[i].compressed     = 1;
@@ -1727,7 +1727,7 @@ static int map_cache_write(struct map_data *m) {
 			map_cache.head.filesize += len_new;
 			map_cache.dirty = 1;
 			if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
-				free(write_buf);
+				aFree(write_buf);
 			}
 			return 0;
 		}
@@ -1819,7 +1819,8 @@ static int map_readafm(int m,char *fn) {
 		map[m].m = m;
 		xs = map[m].xs = afm_size[0];
 		ys = map[m].ys = afm_size[1];
-		map[m].gat = aCalloc(s = map[m].xs * map[m].ys, 1);
+		// check this, unsigned where it might not need to be
+		map[m].gat = (unsigned char*)aCallocA(s = map[m].xs * map[m].ys, 1);
 
 		if(map[m].gat==NULL){
 			printf("out of memory : map_readmap gat\n");
@@ -1842,14 +1843,14 @@ static int map_readafm(int m,char *fn) {
 		map[m].bxs=(xs+BLOCK_SIZE-1)/BLOCK_SIZE;
 		map[m].bys=(ys+BLOCK_SIZE-1)/BLOCK_SIZE;
 		size = map[m].bxs * map[m].bys * sizeof(struct block_list*);
-		map[m].block = aCalloc(size, 1);
+		map[m].block = (struct block_list**)aCalloc(size, 1);
 
 		if(map[m].block == NULL){
 			printf("out of memory : map_readmap block\n");
 			exit(1);
 		}
 
-		map[m].block_mob = aCalloc(size, 1);
+		map[m].block_mob = (struct block_list**)aCalloc(size, 1);
 		if (map[m].block_mob == NULL) {
 			printf("out of memory : map_readmap block_mob\n");
 			exit(1);
@@ -1857,14 +1858,14 @@ static int map_readafm(int m,char *fn) {
 
 		size = map[m].bxs*map[m].bys*sizeof(int);
 
-		map[m].block_count = aCalloc(size, 1);
+		map[m].block_count = (int*)aCallocA(size, 1);
 		if(map[m].block_count==NULL){
 			printf("out of memory : map_readmap block\n");
 			exit(1);
 		}
 		memset(map[m].block_count,0,size);
 
-		map[m].block_mob_count=aCalloc(size, 1);
+		map[m].block_mob_count = (int*)aCallocA(size, 1);
 		if(map[m].block_mob_count==NULL){
 			printf("out of memory : map_readmap block_mob\n");
 			exit(1);
@@ -1885,9 +1886,9 @@ static int map_readafm(int m,char *fn) {
  * マップ1枚読み込み
  * ===================================================*/
 static int map_readmap(int m,char *fn, char *alias, int *map_cache, int maxmap) {
-	unsigned char *gat="";
+	char *gat="";
 	size_t size;
-	
+
 	int i = 0;
 	int e = 0;
 	char progress[21] = "                    ";
@@ -1925,19 +1926,20 @@ static int map_readmap(int m,char *fn, char *alias, int *map_cache, int maxmap)
 		int s;
 		int wh;
 		int x,y,xs,ys;
-		struct gat_1cell {float high[4]; int type;} *p=NULL;	
+		struct gat_1cell {float high[4]; int type;} *p=NULL;
 		// read & convert fn
-		gat=grfio_read(fn);
+		// again, might not need to be unsigned char
+		gat = grfio_read(fn);
 		if(gat==NULL) {
 			return -1;
 			// さすがにマップが読めないのはまずいので終了する
 			//printf("Can't load map %s\n",fn);
 			//exit(1);
 		}
-	
+
 		xs=map[m].xs=*(int*)(gat+6);
 		ys=map[m].ys=*(int*)(gat+10);
-		map[m].gat = (unsigned char *)aCalloc(s = map[m].xs * map[m].ys,sizeof(unsigned char));
+		map[m].gat = (char *)aCallocA(s = map[m].xs * map[m].ys,sizeof(char));
 		wh=map_waterheight(map[m].name);
 		for(y=0;y<ys;y++){
 			p=(struct gat_1cell*)(gat+y*xs*20+14);
@@ -1952,7 +1954,7 @@ static int map_readmap(int m,char *fn, char *alias, int *map_cache, int maxmap)
 			}
 		}
 		map_cache_write(&map[m]);
-		free(gat);
+		aFree(gat);
 	}
 
 	map[m].m=m;
@@ -1967,8 +1969,8 @@ static int map_readmap(int m,char *fn, char *alias, int *map_cache, int maxmap)
 	map[m].block = (struct block_list **)aCalloc(1,size);
 	map[m].block_mob = (struct block_list **)aCalloc(1,size);
 	size = map[m].bxs*map[m].bys*sizeof(int);
-	map[m].block_count = (int *)aCalloc(1,size);
-	map[m].block_mob_count=(int *)aCalloc(1,size);
+	map[m].block_count = (int *)aCallocA(1,size);
+	map[m].block_mob_count=(int *)aCallocA(1,size);
 	if (alias)
            strdb_insert(map_db,alias,&map[m]);
         else
@@ -1990,7 +1992,7 @@ int map_readallmap(void) {
 	FILE *afm_file;
 #endif
 	int map_cache = 0;
-	
+
 	// マップキャッシュを開く
 	if(map_read_flag >= READ_FROM_BITMAP) {
 		map_cache_open(map_bitmap_filename);
@@ -2032,7 +2034,7 @@ int map_readallmap(void) {
 				char buf[64];
 				*p++ = '\0';
 				sprintf(buf,"data\\%s", p);
-				map[i].alias = strdup(buf);
+				map[i].alias = aStrdup(buf);
 			} else
 				map[i].alias = NULL;
 
@@ -2041,20 +2043,20 @@ int map_readallmap(void) {
 				map_delmap(map[i].name);
 				maps_removed++;
 				i--;
-			} 
+			}
 		}
 	}
 
-	free(waterlist);
+	aFree(waterlist);
 	printf("\r");
 	snprintf(tmp_output,sizeof(tmp_output),"Successfully loaded '"CL_WHITE"%d"CL_RESET"' maps.%30s\n",map_num,"");
 	ShowInfo(tmp_output);
-	
+
 	map_cache_close();
 	if(map_read_flag == CREATE_BITMAP || map_read_flag == CREATE_BITMAP_COMPRESSED) {
 		--map_read_flag;
 	}
-	
+
 	if (maps_removed) {
 		snprintf(tmp_output,sizeof(tmp_output),"Maps Removed: '"CL_WHITE"%d"CL_RESET"'\n",maps_removed);
 		ShowNotice(tmp_output);
@@ -2119,15 +2121,15 @@ int parse_console(char *buf) {
     int m, n;
     struct map_session_data *sd;
 
-    sd = aCalloc(sizeof(*sd), 1);
+    sd = (struct map_session_data*)aCalloc(sizeof(*sd), 1);
 
     sd->fd = 0;
     strcpy( sd->status.name , "console");
 
-    type = (char *)aMalloc(64);
-    command = (char *)aMalloc(64);
-    map = (char *)aMalloc(64);
-    buf2 = (char *)aMalloc(72);
+    type = (char *)aMallocA(64);
+    command = (char *)aMallocA(64);
+    map = (char *)aMallocA(64);
+    buf2 = (char *)aMallocA(72);
 
     memset(type,0,64);
     memset(command,0,64);
@@ -2184,12 +2186,12 @@ int parse_console(char *buf) {
     }
 
     end:
-    free(buf);
-    free(type);
-    free(command);
-    free(map);
-    free(buf2);
-    free(sd);
+    aFree(buf);
+    aFree(type);
+    aFree(command);
+    aFree(map);
+    aFree(buf2);
+    aFree(sd);
 
     return 0;
 }
@@ -2317,7 +2319,7 @@ int inter_config_read(char *cfgName)
 		if(i!=2)
 			continue;
 		if(strcmpi(w1,"stall_time")==0){
-			stall_time_ = atoi(w2);			
+			stall_time_ = atoi(w2);
 	#ifndef TXT_ONLY
 		} else if(strcmpi(w1,"item_db_db")==0){
 			strcpy(item_db_db,w2);
@@ -2484,7 +2486,7 @@ void char_online_check(void)
 	chrif_char_reset_offline();
 
 	for(i=0;i<fd_max;i++){
-		if (session[i] && (sd = session[i]->session_data) && sd && sd->state.auth &&
+		if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) && sd && sd->state.auth &&
 		 !(battle_config.hide_GM_session && pc_isGM(sd)))
 			if(sd->status.char_id) {
 				 chrif_char_online(sd);
@@ -2523,21 +2525,22 @@ int flush_timer(int tid, unsigned int tick, int id, int data){
 int id_db_final(void *k,void *d,va_list ap)
 {
 	struct mob_data *id;
-	nullpo_retr(0, id=d);
+	nullpo_retr(0, id = (struct mob_data*)d);
 	if(id->lootitem)
-		free(id->lootitem);
+		aFree(id->lootitem);
 	if(id)
-		free(id);
+		aFree(id);
 	return 0;
 }
+
 int map_db_final(void *k,void *d,va_list ap)
 {
 	struct map_data *id;
-	nullpo_retr(0, id=d);
+	nullpo_retr(0, id = (struct map_data*)d);
 	if(id->gat)
-		free(id->gat);
+		aFree(id->gat);
 	if(id)
-		free(id);
+		aFree(id);
 	return 0;
 }
 int nick_db_final(void *k,void *d,va_list ap){ return 0; }
@@ -2607,14 +2610,14 @@ void do_final(void) {
 	do_final_guild();
 /*
 	for(i=0;i<map_num;i++){
-		if(map[i].gat) {	
-			free(map[i].gat);
+		if(map[i].gat) {
+			aFree(map[i].gat);
 			map[i].gat=NULL; //isn't it NULL already o_O?
 		}
-		if(map[i].block) free(map[i].block);
-		if(map[i].block_mob) free(map[i].block_mob);
-		if(map[i].block_count) free(map[i].block_count);
-		if(map[i].block_mob_count) free(map[i].block_mob_count);
+		if(map[i].block) aFree(map[i].block);
+		if(map[i].block_mob) aFree(map[i].block_mob);
+		if(map[i].block_count) aFree(map[i].block_count);
+		if(map[i].block_mob_count) aFree(map[i].block_mob_count);
 	}
 */
 #endif
@@ -2676,15 +2679,19 @@ int do_init(int argc, char *argv[]) {
 	FILE *data_conf;
 	char line[1024], w1[1024], w2[1024];
 
-	unsigned char *INTER_CONF_NAME="conf/inter_athena.conf";
-	unsigned char *LOG_CONF_NAME="conf/log_athena.conf";
-	unsigned char *MAP_CONF_NAME = "conf/map_athena.conf";
-	unsigned char *BATTLE_CONF_FILENAME = "conf/battle_athena.conf";
-	unsigned char *ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf";
-	unsigned char *CHARCOMMAND_CONF_FILENAME = "conf/charcommand_athena.conf";
-	unsigned char *SCRIPT_CONF_NAME = "conf/script_athena.conf";
-	unsigned char *MSG_CONF_NAME = "conf/msg_athena.conf";
-	unsigned char *GRF_PATH_FILENAME = "conf/grf-files.txt";
+#ifdef DGCOLLECT
+	GC_enable_incremental();
+#endif
+
+	char *INTER_CONF_NAME="conf/inter_athena.conf";
+	char *LOG_CONF_NAME="conf/log_athena.conf";
+	char *MAP_CONF_NAME = "conf/map_athena.conf";
+	char *BATTLE_CONF_FILENAME = "conf/battle_athena.conf";
+	char *ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf";
+	char *CHARCOMMAND_CONF_FILENAME = "conf/charcommand_athena.conf";
+	char *SCRIPT_CONF_NAME = "conf/script_athena.conf";
+	char *MSG_CONF_NAME = "conf/msg_athena.conf";
+	char *GRF_PATH_FILENAME = "conf/grf-files.txt";
 
 	chrif_connected = 0;
 
@@ -2711,10 +2718,10 @@ int do_init(int argc, char *argv[]) {
 			GRF_PATH_FILENAME = argv[i+1];
 #ifndef TXT_ONLY
 		else if (strcmp(argv[i],"--inter_config") == 0 || strcmp(argv[i],"--inter-config") == 0)
-		    INTER_CONF_NAME = argv[i+1];	
+		    INTER_CONF_NAME = argv[i+1];
 #endif /* not TXT_ONLY */
 		else if (strcmp(argv[i],"--log_config") == 0 || strcmp(argv[i],"--log-config") == 0)
-		    LOG_CONF_NAME = argv[i+1];	
+		    LOG_CONF_NAME = argv[i+1];
 		else if (strcmp(argv[i],"--run_once") == 0)	// close the map-server as soon as its done.. for testing [Celest]
 			runflag = 0;
 	}

+ 6 - 5
src/map/map.h

@@ -329,7 +329,7 @@ struct map_session_data {
 	unsigned short eventcount; // [celest]
 
 	int last_skillid,last_skilllv;		// Added by RoVeRT
-	
+
 	unsigned char change_level; // [celest]
 
 #ifndef TXT_ONLY
@@ -414,6 +414,7 @@ struct mob_data {
 		unsigned walk_easy : 1;
 		unsigned special_mob_ai : 3;
 		unsigned soul_change_flag : 1; // Celest
+		int provoke_flag; // Celest
 	} state;
 	int timer;
 	short to_x,to_y;
@@ -509,7 +510,7 @@ enum {
 
 struct map_data {
 	char name[24];
-	unsigned char *gat;	// NULLなら下のmap_data_other_serverとして扱う
+	char *gat;	// NULLなら下のmap_data_other_serverとして扱う
 	char *alias; // [MouseJstr]
 	int *gat_fileused[MAX_CELL_TYPE+1+1]; //もしビットマップを使うならこちらを使う、
 						//上のgatはキャストされてgat_fileused[0]に指す
@@ -562,7 +563,7 @@ struct map_data {
 };
 struct map_data_other_server {
 	char name[24];
-	unsigned char *gat;	// NULL固定にして判断
+	char *gat;	// NULL固定にして判断
 	unsigned long ip;
 	unsigned int port;
 };
@@ -634,7 +635,7 @@ enum {
  * CHELL_CHKTOUCH:セルはタッチ系の場合は1を返す、以外は0
  * CELL_CHKTYPE: セルのタイプを知りたい場合は1を返す、以外は0
 */
-typedef enum { 
+typedef enum {
 	CELL_CHKPASS,CELL_CHKNOPASS,CELL_CHKWATER=3,CELL_CHKHIGH=5,CELL_CHKTOUCH,CELL_CHKTYPE
 } CELL_CHK;
 
@@ -671,7 +672,7 @@ extern int night_flag; // 0=day, 1=night [Yor]
 int map_getcell(int,int,int,CELL_CHK);
 int map_getcellp(struct map_data*,int,int,CELL_CHK);
 extern int map_read_flag;	//セル情報のソース判定フラグ、0ならgrfファイル、1ならビットマップファイル
-enum { 
+enum {
 	READ_FROM_GAT, READ_FROM_AFM,
 	READ_FROM_BITMAP, CREATE_BITMAP,
 	READ_FROM_BITMAP_COMPRESSED, CREATE_BITMAP_COMPRESSED

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 221 - 217
src/map/mob.c


+ 3 - 3
src/map/mob.h

@@ -83,13 +83,13 @@ enum {
 int mobdb_searchname(const char *str);
 int mobdb_checkid(const int id);
 int mob_once_spawn(struct map_session_data *sd,char *mapname,
-	int x,int y,const char *mobname,int class,int amount,const char *event);
+	int x,int y,const char *mobname,int class_,int amount,const char *event);
 int mob_once_spawn_area(struct map_session_data *sd,char *mapname,
 	int x0,int y0,int x1,int y1,
-	const char *mobname,int class,int amount,const char *event);
+	const char *mobname,int class_,int amount,const char *event);
 
 int mob_spawn_guardian(struct map_session_data *sd,char *mapname,	// Spawning Guardians [Valaris]
-	int x,int y,const char *mobname,int class,int amount,const char *event,int guardian);	// Spawning Guardians [Valaris]
+	int x,int y,const char *mobname,int class_,int amount,const char *event,int guardian);	// Spawning Guardians [Valaris]
 
 
 int mob_walktoxy(struct mob_data *md,int x,int y,int easy);

+ 113 - 113
src/map/npc.c

@@ -68,7 +68,7 @@ int npc_enable_sub( struct block_list *bl, va_list ap )
 {
 	struct map_session_data *sd;
 	struct npc_data *nd;
-	char *name=(char *)aCalloc(50,sizeof(char));
+	char *name=(char *)aCallocA(50,sizeof(char));
 
 	nullpo_retr(0, bl);
 	nullpo_retr(0, ap);
@@ -84,7 +84,7 @@ int npc_enable_sub( struct block_list *bl, va_list ap )
 		sd->areanpc_id=nd->bl.id;
 		npc_event(sd,strcat(name,"::OnTouch"),0);
 	}
-	free(name);
+	aFree(name);
 	return 0;
 }
 int npc_enable(const char *name,int flag)
@@ -92,7 +92,7 @@ int npc_enable(const char *name,int flag)
 	struct npc_data *nd=strdb_search(npcname_db,name);
 	if (nd==NULL)
 		return 0;
-	
+
 	if (flag&1) {	// 有効化
 		nd->flag&=~1;
 		clif_spawnnpc(nd);
@@ -132,7 +132,7 @@ int npc_event_dequeue(struct map_session_data *sd)
 
 	sd->npc_id=0;
 	if (sd->eventqueue[0][0]) {	// キューのイベント処理
-		char *name=(char *)aCalloc(50,sizeof(char));
+		char *name=(char *)aCallocA(50,sizeof(char));
 		int i;
 
 		memcpy(name,sd->eventqueue[0],50);
@@ -164,9 +164,9 @@ int npc_event_timer(int tid,unsigned int tick,int id,int data)
 	struct map_session_data *sd=map_id2sd(id);
 	if (sd==NULL)
 		return 0;
-	
+
 	npc_event(sd,(const char *)data,0);
-	free((void*)data);
+	aFree((void*)data);
 	return 0;
 }
 
@@ -226,7 +226,7 @@ int npc_timer(int tid,unsigned int tick,int id,int data)	// Added by RoVeRT
 {
 	strdb_foreach(npcname_db,npc_timer_sub);
 
-	free((void*)data);
+	aFree((void*)data);
 	return 0;
 }*/
 /*==========================================
@@ -239,14 +239,14 @@ int npc_event_export(void *key,void *data,va_list ap)
 	char *lname=(char *)key;
 	int pos=(int)data;
 	struct npc_data *nd=va_arg(ap,struct npc_data *);
-	
+
 	if ((lname[0]=='O' || lname[0]=='o')&&(lname[1]=='N' || lname[1]=='n')) {
 		struct event_data *ev;
 		char *buf;
 		char *p=strchr(lname,':');
 		// エクスポートされる
 		ev=aCalloc(sizeof(struct event_data), 1);
-		buf=aCalloc(50, 1);
+		buf=aCallocA(50, 1);
 		if (ev==NULL || buf==NULL) {
 			printf("npc_event_export: out of memory !\n");
 			exit(1);
@@ -344,17 +344,17 @@ int npc_event_doall_sub(void *key,void *data,va_list ap)
 		run_script(ev->nd->u.scr.script,ev->pos,0,ev->nd->bl.id);
 		(*c)++;
 	}
-	
+
 	return 0;
 }
 int npc_event_doall(const char *name)
 {
 	int c=0;
 	char buf[64]="::";
-	
+
 	strncpy(buf+2,name,62);
 	strdb_foreach(ev_db,npc_event_doall_sub,&c,buf);
-	return c;	
+	return c;
 }
 
 int npc_event_do_sub(void *key,void *data,va_list ap)
@@ -380,7 +380,7 @@ int npc_event_do_sub(void *key,void *data,va_list ap)
 int npc_event_do(const char *name)
 {
 	int c=0;
-	
+
 	if (*name==':' && name[1]==':') {
 		return npc_event_doall(name+2);
 	}
@@ -400,7 +400,7 @@ int npc_event_do_clock(int tid,unsigned int tick,int id,int data)
 	char buf[64];
         char *day="";
 	int c=0;
-	
+
 	time(&timer);
 	t=localtime(&timer);
 
@@ -413,7 +413,7 @@ int npc_event_do_clock(int tid,unsigned int tick,int id,int data)
 	case 5: day = "Fri"; break;
 	case 6: day = "Sat"; break;
 	}
-	
+
 	if (t->tm_min != ev_tm_b.tm_min ) {
 		sprintf(buf,"OnMinute%02d",t->tm_min);
 		c+=npc_event_doall(buf);
@@ -460,7 +460,7 @@ int npc_addeventtimer(struct npc_data *nd,int tick,const char *name)
 		if( nd->eventtimer[i]==-1 )
 			break;
 	if(i<MAX_EVENTTIMER){
-		char *evname=aMalloc(24);
+		char *evname=aMallocA(24);
 		if(evname==NULL){
 			printf("npc_addeventtimer: out of memory !\n");exit(1);
 		}
@@ -541,12 +541,12 @@ int npc_timerevent_import(void *key,void *data,va_list ap)
 	int pos=(int)data;
 	struct npc_data *nd=va_arg(ap,struct npc_data *);
 	int t=0,i=0;
-	
+
 	if(sscanf(lname,"OnTimer%d%n",&t,&i)==1 && lname[i]==':') {
 		// タイマーイベント
 		struct npc_timerevent_list *te=nd->u.scr.timer_event;
 		int j,i=nd->u.scr.timeramount;
-		if(te==NULL) te=aMalloc(sizeof(struct npc_timerevent_list));
+		if(te==NULL) te=aMallocA(sizeof(struct npc_timerevent_list));
 		else te=aRealloc( te, sizeof(struct npc_timerevent_list) * (i+1) );
 		if(te==NULL){
 			printf("npc_timerevent_import: out of memory !\n");
@@ -581,7 +581,7 @@ int npc_timerevent(int tid,unsigned int tick,int id,int data)
 	nd->u.scr.timertick=tick;
 	te=nd->u.scr.timer_event+ nd->u.scr.nexttimer;
 	nd->u.scr.timerid = -1;
-	
+
 	t = nd->u.scr.timer+=data;
 	nd->u.scr.nexttimer++;
 	if( nd->u.scr.timeramount>nd->u.scr.nexttimer ){
@@ -605,7 +605,7 @@ int npc_timerevent_start(struct npc_data *nd, int rid)
 	n=nd->u.scr.timeramount;
 	if( nd->u.scr.nexttimer>=0 || n==0 )
 		return 0;
-	
+
 	for(j=0;j<n;j++){
 		if( nd->u.scr.timer_event[j].timer > nd->u.scr.timer )
 			break;
@@ -617,7 +617,7 @@ int npc_timerevent_start(struct npc_data *nd, int rid)
 	nd->u.scr.timertick=gettick();
 	if (rid >= 0) nd->u.scr.rid=rid;	// changed to: attaching to given rid by default [Shinomori]
 	// if rid is less than 0 leave it unchanged [celest]
-	
+
 	next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
 	nd->u.scr.timerid = add_timer(gettick()+next,npc_timerevent,nd->bl.id,next);
 	return 0;
@@ -743,7 +743,7 @@ int npc_event(struct map_session_data *sd,const char *eventname,int mob_kill)
 		npc_event_dequeue(sd);
 		return 0;
 	}
-	
+
 	sd->npc_id=nd->bl.id;
 	sd->npc_pos=run_script(nd->u.scr.script,ev->pos,sd->bl.id,nd->bl.id);
 	return 0;
@@ -764,7 +764,7 @@ int npc_command_sub(void *key,void *data,va_list ap)
 		if (strcmp(command,temp)==0)
 			run_script(ev->nd->u.scr.script,ev->pos,0,ev->nd->bl.id);
 	}
-	
+
 	return 0;
 }
 
@@ -793,7 +793,7 @@ int npc_touch_areanpc(struct map_session_data *sd,int m,int x,int y)
 			f=0;
 			continue;
 		}
-	
+
 		switch(map[m].npc[i]->bl.subtype) {
 		case WARP:
 			xs=map[m].npc[i]->u.warp.xs;
@@ -824,7 +824,7 @@ int npc_touch_areanpc(struct map_session_data *sd,int m,int x,int y)
 		break;
 	case SCRIPT:
 		{
-			char *name=(char *)aCalloc(50,sizeof(char));
+			char *name=(char *)aCallocA(50,sizeof(char));
 
 			memcpy(name,map[m].npc[i]->name,50);
 			if(sd->areanpc_id==map[m].npc[i]->bl.id)
@@ -832,7 +832,7 @@ int npc_touch_areanpc(struct map_session_data *sd,int m,int x,int y)
 			sd->areanpc_id=map[m].npc[i]->bl.id;
 			if(npc_event(sd,strcat(name,"::OnTouch"),0)>0)
 				npc_click(sd,map[m].npc[i]->bl.id);
-			free(name);
+			aFree(name);
 			break;
 		}
 	}
@@ -855,7 +855,7 @@ int npc_checknear(struct map_session_data *sd,int id)
 			printf("no such npc : %d\n",id);
 		return 1;
 	}
-	
+
 	if (nd->class_<0)	// イベント系は常にOK
 		return 0;
 
@@ -968,7 +968,7 @@ int npc_buylist(struct map_session_data *sd,int n,unsigned short *item_list)
 {
 	struct npc_data *nd;
 	double z;
-	int i,j,w,skill,itemamount=0,new=0;
+	int i,j,w,skill,itemamount=0,new_=0;
 
 	nullpo_retr(3, sd);
 	nullpo_retr(3, item_list);
@@ -998,7 +998,7 @@ int npc_buylist(struct map_session_data *sd,int n,unsigned short *item_list)
 		case ADDITEM_EXIST:
 			break;
 		case ADDITEM_NEW:
-			new++;
+			new_++;
 			break;
 		case ADDITEM_OVERAMOUNT:
 			return 2;
@@ -1010,7 +1010,7 @@ int npc_buylist(struct map_session_data *sd,int n,unsigned short *item_list)
 		return 1;	// zeny不足
 	if (w+sd->weight > sd->max_weight)
 		return 2;	// 重量超過
-	if (pc_inventoryblank(sd)<new)
+	if (pc_inventoryblank(sd)<new_)
 		return 3;	// 種類数超過
 
 	pc_payzeny(sd,(int)z);
@@ -1192,7 +1192,7 @@ static int npc_walk(struct npc_data *nd,unsigned int tick,int data)
 
 		if(nd->walkpath.path_pos>=nd->walkpath.path_len)
 			clif_fixnpcpos(nd);	// When npc stops, retransmission current of a position.
-		
+
 	}
 	return 0;
 }
@@ -1237,7 +1237,7 @@ static int npc_walktimer(int tid,unsigned int tick,int id,int data)
 	if(nd->walktimer != tid){
 		return 0;
 	}
-	
+
 	nd->walktimer=-1;
 
 	if(nd->bl.prev == NULL)
@@ -1302,7 +1302,7 @@ int npc_stop_walking(struct npc_data *nd,int type)
 
 	if(nd->state.state == MS_WALK || nd->state.state == MS_IDLE) {
 		int dx=0,dy=0;
-		
+
 		nd->walkpath.path_len=0;
 		if(type&4){
 			dx=nd->to_x-nd->bl.x;
@@ -1352,7 +1352,7 @@ void npc_clearsrcfile()
 	while( p ) {
 		struct npc_src_list *p2=p;
 		p=p->next;
-		free(p2);
+		aFree(p2);
 	}
 	npc_src_first=NULL;
 	npc_src_last=NULL;
@@ -1363,7 +1363,7 @@ void npc_clearsrcfile()
  */
 void npc_addsrcfile(char *name)
 {
-	struct npc_src_list *new;
+	struct npc_src_list *new_;
 	size_t len;
 
 	if ( strcmpi(name,"clear")==0 ) {
@@ -1382,16 +1382,16 @@ void npc_addsrcfile(char *name)
 		}
 	}
 
-	len = sizeof(*new) + strlen(name);
-	new=(struct npc_src_list *)aCalloc(1,len);
-	new->next = NULL;
-	strncpy(new->name,name,strlen(name)+1);
+	len = sizeof(*new_) + strlen(name);
+	new_=(struct npc_src_list *)aCalloc(1,len);
+	new_->next = NULL;
+	strncpy(new_->name,name,strlen(name)+1);
 	if (npc_src_first==NULL)
-		npc_src_first = new;
+		npc_src_first = new_;
 	if (npc_src_last)
-		npc_src_last->next = new;
+		npc_src_last->next = new_;
 
-	npc_src_last=new;
+	npc_src_last=new_;
 }
 /*==========================================
  * 読み込むnpcファイルの削除
@@ -1411,7 +1411,7 @@ void npc_delsrcfile(char *name)
 			*lp=p->next;
 			if ( npc_src_last==p )
 				npc_src_last=pp;
-			free(p);
+			aFree(p);
 			break;
 		}
 	}
@@ -1525,7 +1525,7 @@ static int npc_parse_shop(char *w1,char *w2,char *w3,char *w4)
 		p=strchr(p,',');
 	}
 	if (pos == 0) {
-		free(nd);
+		aFree(nd);
 		return 1;
 	}
 	nd->u.shop_item[pos++].nameid = 0;
@@ -1545,7 +1545,7 @@ static int npc_parse_shop(char *w1,char *w2,char *w3,char *w4)
 	nd->opt1 = 0;
 	nd->opt2 = 0;
 	nd->opt3 = 0;
-	
+
 	nd = (struct npc_data *)aRealloc(nd,
 		sizeof(struct npc_data) + sizeof(nd->u.shop_item[0]) * pos);
 
@@ -1572,14 +1572,14 @@ int npc_convertlabel_db(void *key,void *data,va_list ap)
 	struct npc_label_list *lst;
 	int num;
 	char *p=strchr(lname,':');
-	
+
 	nullpo_retr(0, ap);
 	nullpo_retr(0, nd=va_arg(ap,struct npc_data *));
 
 	lst=nd->u.scr.label_list;
 	num=nd->u.scr.label_list_num;
 	if(!lst){
-		lst=(struct npc_label_list *)aCalloc(1,sizeof(struct npc_label_list));
+		lst=(struct npc_label_list *)aCallocA(1,sizeof(struct npc_label_list));
 		num=0;
 	}else
 		lst=(struct npc_label_list *)aRealloc(lst,sizeof(struct npc_label_list)*(num+1));
@@ -1598,7 +1598,7 @@ int npc_convertlabel_db(void *key,void *data,va_list ap)
  */
 static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line,FILE *fp,int *lines)
 {
-	int x,y,dir=0,m,xs=0,ys=0,class=0;	// [Valaris] thanks to fov
+	int x,y,dir=0,m,xs=0,ys=0,class_=0;	// [Valaris] thanks to fov
 	char mapname[24];
 	unsigned char *srcbuf=NULL,*script;
 	int srcsize=65536;
@@ -1627,7 +1627,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 
 	if(strcmp(w2,"script")==0){
 		// スクリプトの解析
-		srcbuf=(char *)aCalloc(srcsize,sizeof(char));
+		srcbuf=(char *)aCallocA(srcsize,sizeof(char));
 	if (strchr(first_line,'{')) {
 		strcpy(srcbuf,strchr(first_line,'{'));
 		startline=*lines;
@@ -1657,13 +1657,13 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 	script=parse_script(srcbuf,startline);
 	if (script==NULL) {
 		// script parse error?
-		free(srcbuf);
+		aFree(srcbuf);
 		return 1;
 	}
 
 	}else{
 		// duplicateする
-		
+
 		char srcname[128];
 		struct npc_data *nd2;
 		if( sscanf(w2,"duplicate(%[^)])",srcname)!=1 ){
@@ -1678,22 +1678,22 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 		label_dup=nd2->u.scr.label_list;
 		label_dupnum=nd2->u.scr.label_list_num;
 		src_id=nd2->bl.id;
-	
+
 	}// end of スクリプト解析
 
 	nd=(struct npc_data *)aCalloc(1,sizeof(struct npc_data));
 
 	if(m==-1){
 		// スクリプトコピー用のダミーNPC
-		
-	}else if( sscanf(w4,"%d,%d,%d",&class,&xs,&ys)==3) {
+
+	}else if( sscanf(w4,"%d,%d,%d",&class_,&xs,&ys)==3) {
 		// 接触型NPC
 		int i,j;
-		
+
 		if (xs>=0)xs=xs*2+1;
 		if (ys>=0)ys=ys*2+1;
-		
-		if (class>=0) {
+
+		if (class_>=0) {
 
 			for(i=0;i<ys;i++) {
 				for(j=0;j<xs;j++) {
@@ -1703,16 +1703,16 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 				}
 			}
 		}
-		
+
 		nd->u.scr.xs=xs;
 		nd->u.scr.ys=ys;
 	} else {	// クリック型NPC
-		class=atoi(w4);
+		class_=atoi(w4);
 		nd->u.scr.xs=0;
 		nd->u.scr.ys=0;
 	}
-	
-	if (class<0 && m>=0) {	// イベント型NPC
+
+	if (class_<0 && m>=0) {	// イベント型NPC
 		evflag=1;
 	}
 
@@ -1735,7 +1735,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 	nd->bl.id=npc_get_new_npc_id();
 	nd->dir = dir;
 	nd->flag=0;
-	nd->class_=class;
+	nd->class_=class_;
 	nd->speed=200;
 	nd->u.scr.script=script;
 	nd->u.scr.src_id=src_id;
@@ -1766,21 +1766,21 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 
 
 	//-----------------------------------------
-	// ラベルデータの準備	
+	// ラベルデータの準備
 	if(srcbuf){
 		// script本体がある場合の処理
-		
+
 		// ラベルデータのコンバート
 	label_db=script_get_label_db();
 		strdb_foreach(label_db,npc_convertlabel_db,nd);
-	
+
 		// もう使わないのでバッファ解放
-		free(srcbuf);
+		aFree(srcbuf);
 
 	}else{
 		// duplicate
 
-//		nd->u.scr.label_list=aMalloc(sizeof(struct npc_label_list)*label_dupnum);
+//		nd->u.scr.label_list=aMallocA(sizeof(struct npc_label_list)*label_dupnum);
 //		memcpy(nd->u.scr.label_list,label_dup,sizeof(struct npc_label_list)*label_dupnum);
 
 		nd->u.scr.label_list=label_dup;	// ラベルデータ共有
@@ -1792,13 +1792,13 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 	for(i=0;i<nd->u.scr.label_list_num;i++){
 		char *lname=nd->u.scr.label_list[i].name;
 		int pos=nd->u.scr.label_list[i].pos;
-	
+
 		if ((lname[0]=='O' || lname[0]=='o')&&(lname[1]=='N' || lname[1]=='n')) {
 			struct event_data *ev;
 			char *buf;
 			// エクスポートされる
 			ev=(struct event_data *)aCalloc(1,sizeof(struct event_data));
-			buf=(char *)aCalloc(50,sizeof(char));
+			buf=(char *)aCallocA(50,sizeof(char));
 			if (strlen(lname)>24) {
 				printf("npc_parse_script: label name error !\n");
 				exit(1);
@@ -1810,7 +1810,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 			}
 		}
 	}
-	
+
 	//-----------------------------------------
 	// ラベルデータからタイマーイベント取り込み
 	for(i=0;i<nd->u.scr.label_list_num;i++){
@@ -1822,7 +1822,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 			struct npc_timerevent_list *te=nd->u.scr.timer_event;
 			int j,k=nd->u.scr.timeramount;
 			if(te==NULL)
-				te=(struct npc_timerevent_list *)aCalloc(1,sizeof(struct npc_timerevent_list));
+				te=(struct npc_timerevent_list *)aCallocA(1,sizeof(struct npc_timerevent_list));
 			else
 				te=(struct npc_timerevent_list *)aRealloc( te, sizeof(struct npc_timerevent_list) * (k+1) );
 			for(j=0;j<k;j++){
@@ -1840,7 +1840,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
 	nd->u.scr.nexttimer=-1;
 	nd->u.scr.timerid=-1;
 
-	
+
 	return 0;
 }
 
@@ -1859,7 +1859,7 @@ static int npc_parse_function(char *w1,char *w2,char *w3,char *w4,char *first_li
 	char *p;
 
 	// スクリプトの解析
-	srcbuf=(char *)aCalloc(srcsize,sizeof(char));
+	srcbuf=(char *)aCallocA(srcsize,sizeof(char));
 	if (strchr(first_line,'{')) {
 		strcpy(srcbuf,strchr(first_line,'{'));
 		startline=*lines;
@@ -1889,11 +1889,11 @@ static int npc_parse_function(char *w1,char *w2,char *w3,char *w4,char *first_li
 	script=parse_script(srcbuf,startline);
 	if (script==NULL) {
 		// script parse error?
-		free(srcbuf);
+		aFree(srcbuf);
 		return 1;
 	}
 
-	p=(char *)aCalloc(50,sizeof(char));
+	p=(char *)aCallocA(50,sizeof(char));
 
 	strncpy(p,w3,50);
 	strdb_insert(script_get_userfunc_db(),p,script);
@@ -1901,10 +1901,10 @@ static int npc_parse_function(char *w1,char *w2,char *w3,char *w4,char *first_li
 //	label_db=script_get_label_db();
 
 	// もう使わないのでバッファ解放
-	free(srcbuf);
-	
+	aFree(srcbuf);
+
 //	printf("function %s => %p\n",p,script);
-	
+
 	return 0;
 }
 
@@ -1915,7 +1915,7 @@ static int npc_parse_function(char *w1,char *w2,char *w3,char *w4,char *first_li
  */
 int npc_parse_mob(char *w1,char *w2,char *w3,char *w4)
 {
-	int m,x,y,xs,ys,class,num,delay1,delay2,level;
+	int m,x,y,xs,ys,class_,num,delay1,delay2,level;
 	int i;
 	char mapname[24];
 	char mobname[24];
@@ -1926,7 +1926,7 @@ int npc_parse_mob(char *w1,char *w2,char *w3,char *w4)
 	delay1=delay2=0;
 	// 引数の個数チェック
 	if (sscanf(w1,"%[^,],%d,%d,%d,%d",mapname,&x,&y,&xs,&ys) < 3 ||
-	   sscanf(w4,"%d,%d,%d,%d,%s",&class,&num,&delay1,&delay2,eventname) < 2 ) {
+	   sscanf(w4,"%d,%d,%d,%d,%s",&class_,&num,&delay1,&delay2,eventname) < 2 ) {
 		printf("bad monster line : %s\n",w3);
 		return 1;
 	}
@@ -1941,13 +1941,13 @@ int npc_parse_mob(char *w1,char *w2,char *w3,char *w4)
 	for(i=0;i<num;i++) {
 		md=(struct mob_data *)aCalloc(1,sizeof(struct mob_data));
 
-		if(class>4000) { // large/tiny mobs [Valaris]
+		if(class_>4000) { // large/tiny mobs [Valaris]
 			md->size=2;
-			class-=4000;
+			class_-=4000;
 		}
-		else if(class>2000) {
+		else if(class_>2000) {
 			md->size=1;
-			class-=2000;
+			class_-=2000;
 		}
 
 		md->bl.prev=NULL;
@@ -1958,9 +1958,9 @@ int npc_parse_mob(char *w1,char *w2,char *w3,char *w4)
 
 		if(sscanf(w3,"%[^,],%d",mobname,&level) > 1) {
 			if(strcmp(mobname,"--en--")==0)
-				memcpy(md->name,mob_db[class].name,24);
+				memcpy(md->name,mob_db[class_].name,24);
 			else if(strcmp(mobname,"--ja--")==0)
-				memcpy(md->name,mob_db[class].jname,24);
+				memcpy(md->name,mob_db[class_].jname,24);
 			md->level=level;
 		}
 
@@ -1968,7 +1968,7 @@ int npc_parse_mob(char *w1,char *w2,char *w3,char *w4)
 		memcpy(md->name,w3,24);
 
 		md->n = i;
-		md->base_class = md->class_ = class;
+		md->base_class = md->class_ = class_;
 		md->bl.id=npc_get_new_npc_id();
 		md->m =m;
 		md->x0=x;
@@ -1982,9 +1982,9 @@ int npc_parse_mob(char *w1,char *w2,char *w3,char *w4)
 		md->timer = -1;
 		md->target_id=0;
 		md->attacked_id=0;
-		md->speed=mob_db[class].speed;
+		md->speed=mob_db[class_].speed;
 
-		if (mob_db[class].mode&0x02)
+		if (mob_db[class_].mode&0x02)
 			md->lootitem=(struct item *)aCalloc(LOOTITEM_SIZE,sizeof(struct item));
 		else
 			md->lootitem=NULL;
@@ -2122,19 +2122,19 @@ static int npc_parse_mapflag(char *w1,char *w2,char *w3,char *w4)
 	}
 	else if (strcmpi(w3,"noicewall")==0) { // noicewall [Valaris]
 		map[m].flag.noicewall=1;
-	}	
+	}
 	else if (strcmpi(w3,"snow")==0) { // snow [Valaris]
 		map[m].flag.snow=1;
-	}	
+	}
 	else if (strcmpi(w3,"fog")==0) { // fog [Valaris]
 		map[m].flag.fog=1;
-	}	
+	}
 	else if (strcmpi(w3,"sakura")==0) { // sakura [Valaris]
 		map[m].flag.sakura=1;
-	}	
+	}
 	else if (strcmpi(w3,"leaves")==0) { // leaves [Valaris]
 		map[m].flag.leaves=1;
-	}	
+	}
 	else if (strcmpi(w3,"rain")==0) { // rain [Valaris]
 		map[m].flag.rain=1;
 	}
@@ -2144,7 +2144,7 @@ static int npc_parse_mapflag(char *w1,char *w2,char *w3,char *w4)
 	else if (strcmpi(w3,"nogo")==0) { // celest
 		map[m].flag.nogo=1;
 	}
-	
+
 	return 0;
 }
 
@@ -2169,12 +2169,12 @@ static int npc_read_indoors(void)
 			if ((m = map_mapname2mapid(map_name)) >= 0)
 				map[m].flag.indoors=1;
 		}
-		
+
 		p=strchr(p,10);
 		if(!p) break;
 		p++;
 	}
-	free(buf);
+	aFree(buf);
 	sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\indoorrswtable.txt");
 	ShowStatus(tmp_output);
 
@@ -2183,9 +2183,9 @@ static int npc_read_indoors(void)
 
 static int ev_db_final(void *key,void *data,va_list ap)
 {
-	free(data);
+	aFree(data);
 	if(strstr(key,"::")!=NULL)
-		free(key);
+		aFree(key);
 	return 0;
 }
 static int npcname_db_final(void *key,void *data,va_list ap)
@@ -2214,49 +2214,49 @@ int do_final_npc(void)
 		if((bl=map_id2bl(i))){
 			if(bl->type == BL_NPC && (nd = (struct npc_data *)bl)){
 				if(nd->chat_id && (cd=(struct chat_data*)map_id2bl(nd->chat_id))){
-					free(cd);
+					aFree(cd);
 					cd = NULL;
 				}
 				if(nd->bl.subtype == SCRIPT){
 					if(nd->u.scr.timer_event)
-						free(nd->u.scr.timer_event);
+						aFree(nd->u.scr.timer_event);
 				 	if(nd->u.scr.src_id==0){
 						if(nd->u.scr.script){
-							free(nd->u.scr.script);
+							aFree(nd->u.scr.script);
 							nd->u.scr.script=NULL;
 						}
 						if(nd->u.scr.label_list){
-							free(nd->u.scr.label_list);
+							aFree(nd->u.scr.label_list);
 							nd->u.scr.label_list = NULL;
 						}
 					}
 				}
-				free(nd);
+				aFree(nd);
 				nd = NULL;
 			}else if(bl->type == BL_MOB && (md = (struct mob_data *)bl)){
 				if(md->lootitem){
-					free(md->lootitem);
+					aFree(md->lootitem);
 					md->lootitem = NULL;
 				}
-				free(md);
+				aFree(md);
 				md = NULL;
 			}else if(bl->type == BL_PET && (pd = (struct pet_data *)bl)){
-				free(pd);
+				aFree(pd);
 				pd = NULL;
 			}
 		}
 	}
-	
+
 	return 0;
 }
 
 
-void ev_release(struct dbn *db, int which) 
+void ev_release(struct dbn *db, int which)
 {
     if (which & 0x1)
-        free(db->key);
+        aFree(db->key);
     if (which & 0x2)
-        free(db->data);
+        aFree(db->data);
 }
 
 /*==========================================
@@ -2281,12 +2281,12 @@ int do_init_npc(void)
 	npcname_db=strdb_init(24);
 
         ev_db->release = ev_release;
-	
+
 	memset(&ev_tm_b,-1,sizeof(ev_tm_b));
 
 	for(nsl=npc_src_first;nsl;nsl=nsl->next) {
 		/*if(nsl->prev){ // [Shinomori]
-			free(nsl->prev);
+			aFree(nsl->prev);
 			nsl->prev = NULL;
 		}*/
 		fp=fopen(nsl->name,"r");

+ 1 - 1
src/map/party.c

@@ -30,7 +30,7 @@ int party_send_xyhp_timer(int tid,unsigned int tick,int id,int data);
  */
 static int party_db_final(void *key,void *data,va_list ap)
 {
-	free(data);
+	aFree(data);
 	return 0;
 }
 void do_final_party(void)

+ 164 - 82
src/map/pc.c

@@ -87,11 +87,11 @@ int pc_isGM(struct map_session_data *sd) {
 	if (p == NULL)
 		return 0;
 	return p->level;*/
-	
+
 	//For console [Wizputer]
 	if ( sd->fd == 0 )
 	    return 99;
-	
+
 	for(i = 0; i < GM_num; i++)
 		if (gm_account[i].account_id == sd->status.account_id)
 			return gm_account[i].level;
@@ -218,7 +218,7 @@ int pc_addspiritball(struct map_session_data *sd,int interval,int max) {
 		sd->spiritball = 0;
 
 	if(sd->spiritball >= max) {
-		if(sd->spirit_timer[0] != -1) 
+		if(sd->spirit_timer[0] != -1)
 			delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
 		memcpy( &sd->spirit_timer[0], &sd->spirit_timer[1], sizeof(sd->spirit_timer[0]) * (sd->spiritball - 1));
 	} else
@@ -554,7 +554,7 @@ int pc_isequip(struct map_session_data *sd,int n)
 
 	item = sd->inventory_data[n];
 	sc_data = battle_get_sc_data(&sd->bl);
-	//s_class = pc_calc_base_job(sd->status.class);
+	//s_class = pc_calc_base_job(sd->status.class_);
 
 	if( battle_config.gm_allequip>0 && pc_isGM(sd)>=battle_config.gm_allequip )
 		return 1;
@@ -599,7 +599,7 @@ int pc_break_equip(struct map_session_data *sd, unsigned short where)
 	struct item_data* item;
 	int i;
 	int sc;
-	char output[255];	
+	char output[255];
 
 	if(sd == NULL)
 		return -1;
@@ -669,7 +669,7 @@ int pc_breakweapon(struct map_session_data *sd)
 			return 1;
 		}
 	}
-	
+
 	return 0;
 }
 /*==========================================
@@ -755,7 +755,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, struct mmo_chars
 	sd->skillitem = -1;
 	sd->skillitemlv = -1;
 	sd->invincible_timer = -1;
-	
+
 	sd->deal_locked = 0;
 	sd->trade_partner = 0;
 
@@ -772,7 +772,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, struct mmo_chars
 
 	sd->doridori_counter = 0;
 
-	sd->change_level = pc_readglobalreg(sd,"jobchange_level");	
+	sd->change_level = pc_readglobalreg(sd,"jobchange_level");
 
 #ifndef TXT_ONLY // mail system [Valaris]
 	if(battle_config.mail_system)
@@ -790,7 +790,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, struct mmo_chars
 		sd->dev.val1[i] = 0;
 		sd->dev.val2[i] = 0;
 	}
-	
+
 	// アカウント??の送信要求
 	intif_request_accountreg(sd);
 
@@ -876,7 +876,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, struct mmo_chars
 	sd->state.event_death = pc_readglobalreg(sd,"PCDieEvent");
 	sd->state.event_kill = pc_readglobalreg(sd,"PCKillEvent");
 	sd->state.event_disconnect = pc_readglobalreg(sd,"PCLogoffEvent");
-		
+
 	if (night_flag == 1 && !map[sd->bl.m].flag.indoors) {
 		char tmpstr[1024];
 		strcpy(tmpstr, msg_txt(500)); // Actually, it's the night...
@@ -1016,7 +1016,7 @@ int pc_calc_skilltree(struct map_session_data *sd)
 	for(i=0;i<MAX_SKILL;i++){
 //                if(skill_get_inf2(i) & 0x01)
 //                        continue;
-		if (sd->status.skill[i].flag != 13)   
+		if (sd->status.skill[i].flag != 13)
 		        sd->status.skill[i].id=0;
 		if (sd->status.skill[i].flag && sd->status.skill[i].flag != 13){	// cardスキルなら、
 			sd->status.skill[i].lv=(sd->status.skill[i].flag==1)?0:sd->status.skill[i].flag-2;	// 本?のlvに
@@ -1030,13 +1030,13 @@ int pc_calc_skilltree(struct map_session_data *sd)
 			sd->status.skill[i].id=i;
 		for(i=210;i<291;i++)
 			sd->status.skill[i].id=i;
-		for(i=304;i<337;i++){
+		for(i=304;i<338;i++){
 			if(i==331) continue;
 			sd->status.skill[i].id=i;
 		}
 		if(battle_config.enable_upper_class){ //confで無?でなければ?み?む
-		for(i=355;i<MAX_SKILL;i++)
-			sd->status.skill[i].id=i;
+			for(i=355;i<411;i++)
+				sd->status.skill[i].id=i;
 		}
 	}else{
             do {
@@ -1052,6 +1052,8 @@ int pc_calc_skilltree(struct map_session_data *sd)
 								break;
 							}
                         }
+						if (id >= 2 && id <= 53 && pc_checkskill(sd, NV_BASIC) < 9)
+							f=0;
                     }
                     if(f && sd->status.skill[id].id==0 ){
                         sd->status.skill[id].id=id;
@@ -1073,7 +1075,7 @@ int pc_calc_skilltree_normalize_job(int c, struct map_session_data *sd) {
 			c = 0;
 		//else if((sd->status.skill_point >= sd->status.job_level && skill_point < 58) && ((c > 6 && c < 23) || (c > 4007 && c < 4023) || (c > 4029 && c < 4045))) {
 		//else if ((sd->status.skill_point >= sd->status.job_level && skill_point < 58) && (c > 6 && c < 23)) {
-		else if ((sd->status.skill_point >= sd->status.job_level && skill_point < sd->change_level+8) && (c > 6 && c < 23)) {
+		else if (sd->status.skill_point >= sd->status.job_level && ((sd->change_level > 0 && skill_point < sd->change_level+8) || skill_point < 58)  && (c > 6 && c < 23)) {
 			switch(c) {
 				case 7:
 				case 13:
@@ -1178,7 +1180,7 @@ int pc_checkweighticon(struct map_session_data *sd)
 		flag=1;
 	if(sd->weight*10 >= sd->max_weight*9)
 		flag=2;
-	
+
 	if(flag==1){
 		if(sd->sc_data[SC_WEIGHT50].timer==-1)
 			skill_status_change_start(&sd->bl,SC_WEIGHT50,0,0,0,0,0,0);
@@ -1670,6 +1672,16 @@ int pc_calcstatus(struct map_session_data* sd,int first)
 				sd->paramb[5] += sd->status.luk+psd->status.luk/2 > 99 ? 99-sd->status.luk : psd->status.luk/2;
 			}
 		}
+		if(sd->sc_data[SC_GOSPEL].timer!=-1 && sd->sc_data[SC_GOSPEL].val4 == BCT_PARTY){
+			if (sd->sc_data[SC_GOSPEL].val3 == 6) {
+				sd->paramb[0]+= 2;
+				sd->paramb[1]+= 2;
+				sd->paramb[2]+= 2;
+				sd->paramb[3]+= 2;
+				sd->paramb[4]+= 2;
+				sd->paramb[5]+= 2;
+			}
+		}
 	}
 
 	//1度も死んでないJob70スパノビに+10
@@ -1769,7 +1781,7 @@ int pc_calcstatus(struct map_session_data* sd,int first)
 	else if (pc_isriding(sd)) {	// ペコペコ?りによる速度?加
 		sd->speed -= (0.25 * DEFAULT_WALK_SPEED);
 		sd->max_weight += 10000;
-	}	
+	}
 	if((skill=pc_checkskill(sd,CR_TRUST))>0) { // フェイス
 		sd->status.max_hp += skill*200;
 		sd->subele[6] += skill*5;
@@ -1788,7 +1800,7 @@ int pc_calcstatus(struct map_session_data* sd,int first)
 			sd->status.max_hp = sd->status.max_hp * 130/100;
 		else if (s_class.upper==2)
 			sd->status.max_hp = sd->status.max_hp * 70/100;
-		
+
 	if(sd->hprate!=100)
 		sd->status.max_hp = sd->status.max_hp*sd->hprate/100;
 
@@ -1910,6 +1922,13 @@ int pc_calcstatus(struct map_session_data* sd,int first)
 		}
 		if(sd->sc_data[SC_POISON].timer!=-1)	// 毒?態
 			sd->def2 = sd->def2*75/100;
+		if(sd->sc_data[SC_CURSE].timer!=-1){
+			sd->base_atk = sd->base_atk*75/100;
+			sd->watk = sd->watk*75/100;
+			index = sd->equip_index[8];
+			if(index >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->type == 4)
+				sd->watk_ = sd->watk_*75/100;
+		}
 		if(sd->sc_data[SC_DRUMBATTLE].timer!=-1){	// ?太鼓の響き
 			sd->watk += sd->sc_data[SC_DRUMBATTLE].val2;
 			sd->def  += sd->sc_data[SC_DRUMBATTLE].val3;
@@ -2113,8 +2132,62 @@ int pc_calcstatus(struct map_session_data* sd,int first)
 			sd->def = 100;
 		if(sd->sc_data[SC_BARRIER].timer!=-1)
 			sd->mdef = 100;
+
+		if(sd->sc_data[SC_GOSPEL].timer!=-1) {
+			if (sd->sc_data[SC_GOSPEL].val4 == BCT_PARTY){
+				switch (sd->sc_data[SC_GOSPEL].val3)
+				{
+				case 4:
+					sd->status.max_hp += sd->status.max_hp * 25 / 100;
+					if(sd->status.max_hp > battle_config.max_hp)
+						sd->status.max_hp = battle_config.max_hp;
+					break;
+				case 5:
+					sd->status.max_sp += sd->status.max_sp * 25 / 100;
+					if(sd->status.max_sp > battle_config.max_sp)
+						sd->status.max_sp = battle_config.max_sp;
+					break;
+				case 11:
+					sd->def += sd->def * 25 / 100;
+					sd->def2 += sd->def2 * 25 / 100;
+					break;
+				case 12:
+					sd->base_atk += sd->base_atk * 8 / 100;
+					break;
+				case 13:
+					sd->flee += sd->flee * 5 / 100;
+					break;
+				case 14:
+					sd->hit += sd->hit * 5 / 100;
+					break;
+				}
+			} else if (sd->sc_data[SC_GOSPEL].val4 == BCT_ENEMY){
+				switch (sd->sc_data[SC_GOSPEL].val3)
+				{
+					case 5:
+						sd->def = 0;
+						sd->def2 = 0;
+						break;
+					case 6:
+						sd->base_atk = 0;
+						sd->watk = 0;
+						sd->watk2 = 0;
+						break;
+					case 7:
+						sd->flee = 0;
+						break;
+					case 8:
+						sd->speed_rate += 75;
+						aspd_rate += 75;
+						break;
+				}
+			}
+		}
 	}
 
+	if (sd->speed_rate <= 0)
+		sd->speed_rate = 1;
+
 	if(sd->speed_rate != 100)
 		sd->speed = sd->speed*sd->speed_rate/100;
 	if(sd->speed < 1) sd->speed = 1;
@@ -2216,7 +2289,7 @@ int pc_calcstatus(struct map_session_data* sd,int first)
 		clif_updatestatus(sd,SP_CARTINFO);*/
 
 	//if(sd->status.hp<sd->status.max_hp>>2 && pc_checkskill(sd,SM_AUTOBERSERK)>0 &&
-	if(sd->status.hp<sd->status.max_hp>>2 && sd->sc_data[SC_AUTOBERSERK].timer != -1 &&			
+	if(sd->status.hp<sd->status.max_hp>>2 && sd->sc_data[SC_AUTOBERSERK].timer != -1 &&
 		(sd->sc_data[SC_PROVOKE].timer==-1 || sd->sc_data[SC_PROVOKE].val2==0 ) && !pc_isdead(sd))
 		// オ?トバ?サ?ク?動
 		skill_status_change_start(&sd->bl,SC_PROVOKE,10,1,0,0,0,0);
@@ -2239,7 +2312,7 @@ int pc_calcspeed (struct map_session_data *sd)
 
 	b_speed = sd->speed;
 	sd->speed = DEFAULT_WALK_SPEED ;
-	
+
 	if(sd->sc_count){
 		if(sd->sc_data[SC_INCREASEAGI].timer!=-1 && sd->sc_data[SC_QUAGMIRE].timer == -1 && sd->sc_data[SC_DONTFORGETME].timer == -1){	// 速度?加
 			sd->speed -= sd->speed *25/100;
@@ -2303,7 +2376,7 @@ int pc_calcspeed (struct map_session_data *sd)
 	if(sd->speed_rate != 100)
 		sd->speed = sd->speed*sd->speed_rate/100;
 	if(sd->speed < 1) sd->speed = 1;
-	
+
 	if(sd->skilltimer != -1 && (skill = pc_checkskill(sd,SA_FREECAST)) > 0) {
 		sd->prev_speed = sd->speed;
 		sd->speed = sd->speed*(175 - skill*5)/100;
@@ -2932,7 +3005,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
 		if(sd->state.lr_flag !=2){
 			sd->random_attack_increase_add = type2;
 			sd->random_attack_increase_per += val;
-		}	
+		}
 		break;
 	case SP_WEAPON_ATK:
 		if(sd->state.lr_flag != 2)
@@ -3662,7 +3735,7 @@ int pc_item_refine(struct map_session_data *sd,int idx)
 	int flag = 1, i = 0, ep = 0, per;
 	int material[5] = { 0, 1010, 1011, 984, 984 };
 	struct item *item;
-	
+
 	nullpo_retr(0, sd);
 	item = &sd->status.inventory[idx];
 
@@ -3681,7 +3754,7 @@ int pc_item_refine(struct map_session_data *sd,int idx)
 			per = percentrefinery [itemdb_wlv (item->nameid)][(int)item->refine];
 			//per += pc_checkskill(sd,BS_WEAPONRESEARCH);
 			per *= (75 + sd->status.job_level/2)/100;
-			
+
 			if (per > rand() % 100) {
 				flag = 0;
 				item->refine++;
@@ -3691,7 +3764,7 @@ int pc_item_refine(struct map_session_data *sd,int idx)
 					pc_unequipitem(sd,idx,3);
 				}
 				clif_refine(sd->fd,sd,0,idx,item->refine);
-				clif_delitem(sd,idx,1);				
+				clif_delitem(sd,idx,1);
 				clif_additem(sd,idx,1,0);
 				if (ep)
 					pc_equipitem(sd,idx,ep);
@@ -3777,7 +3850,7 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl)
 					if(itemid > 0 && itemdb_type(itemid) != 6)
 					{
 						rate = (mob_db[md->class_].dropitem[i].p / battle_config.item_rate_common * 100 * skill)/100;
-						
+
 						if(rand()%10000 < rate)
 						{
 							struct item tmp_item;
@@ -3882,7 +3955,7 @@ int pc_setpos(struct map_session_data *sd,char *mapname_org,int x,int y,int clrt
 		if(sd->sc_data[SC_DANCING].timer!=-1) // clear dance effect when warping [Valaris]
 			skill_stop_dancing(&sd->bl,0);
 	}
-	
+
 	if(sd->status.option&2)
 		skill_status_change_end(&sd->bl, SC_HIDING, -1);
 	if(sd->status.option&4)
@@ -3894,7 +3967,7 @@ int pc_setpos(struct map_session_data *sd,char *mapname_org,int x,int y,int clrt
 		pet_stopattack(sd->pd);
 		pet_changestate(sd->pd,MS_IDLE,0);
 	}
-	
+
 	if(sd->disguise) { // clear disguises when warping [Valaris]
 		clif_clearchar(&sd->bl, 9);
 		disguise=sd->disguise;
@@ -4000,13 +4073,13 @@ int pc_setpos(struct map_session_data *sd,char *mapname_org,int x,int y,int clrt
 
 	if(disguise) // disguise teleport fix [Valaris]
 		sd->disguise=disguise;
-	
+
 	memcpy(sd->mapname,mapname,24);
 	sd->bl.m = m;
 	sd->to_x = x;
 	sd->to_y = y;
 
-	// moved and changed dance effect stopping	
+	// moved and changed dance effect stopping
 
 	sd->bl.x =  x;
 	sd->bl.y =  y;
@@ -4336,19 +4409,19 @@ int pc_walktoxy(struct map_session_data *sd,int x,int y)
 	if (sd->sc_data && sd->status.guild_id > 0) {
 		struct skill_unit *su;
 		struct skill_unit_group *sg;
-		if (sd->state.leadership_flag && (su=(struct skill_unit *)sd->state.leadership_flag) && 
+		if (sd->state.leadership_flag && (su=(struct skill_unit *)sd->state.leadership_flag) &&
 			(sg=su->group) && sg->src_id == sd->bl.id) {
 			skill_unit_move_unit_group(sg,sd->bl.m,(x - sd->bl.x),(y - sd->bl.y));
 		}
-		if (sd->state.glorywounds_flag && (su=(struct skill_unit *)sd->state.glorywounds_flag) && 
+		if (sd->state.glorywounds_flag && (su=(struct skill_unit *)sd->state.glorywounds_flag) &&
 			(sg=su->group) && sg->src_id == sd->bl.id) {
 			skill_unit_move_unit_group(sg,sd->bl.m,(x - sd->bl.x),(y - sd->bl.y));
 		}
-		if (sd->state.soulcold_flag && (su=(struct skill_unit *)sd->state.soulcold_flag) && 
+		if (sd->state.soulcold_flag && (su=(struct skill_unit *)sd->state.soulcold_flag) &&
 			(sg=su->group) && sg->src_id == sd->bl.id) {
 			skill_unit_move_unit_group(sg,sd->bl.m,(x - sd->bl.x),(y - sd->bl.y));
 		}
-		if (sd->state.hawkeyes_flag && (su=(struct skill_unit *)sd->state.hawkeyes_flag) && 
+		if (sd->state.hawkeyes_flag && (su=(struct skill_unit *)sd->state.hawkeyes_flag) &&
 			(sg=su->group) && sg->src_id == sd->bl.id) {
 			skill_unit_move_unit_group(sg,sd->bl.m,(x - sd->bl.x),(y - sd->bl.y));
 		}
@@ -4392,7 +4465,7 @@ int pc_randomwalk(struct map_session_data *sd,int tick)
 {
 	const int retrycount = 20;
 	nullpo_retr(0, sd);
-	
+
 	if(DIFF_TICK(sd->next_walktime,tick)<0){
 		int i,x,y,d;
 		d = rand()%7+5;
@@ -4608,7 +4681,7 @@ struct pc_base_job pc_calc_base_job(int b_class)
 	}else{
 		bj.type = 2;
 	}
-	
+
 	return bj;
 }
 
@@ -4624,7 +4697,7 @@ int pc_calc_base_job2 (int b_class)
 		return b_class - 4001;
 	else if(b_class == 4045)
 		return 23;
-	return b_class - 4023;	
+	return b_class - 4023;
 }
 
 int pc_calc_upper(int b_class)
@@ -4668,8 +4741,12 @@ int pc_attack_timer(int tid,unsigned int tick,int id,int data)
 	if(bl==NULL || bl->prev == NULL)
 		return 0;
 
-	if(bl->type == BL_PC && pc_isdead((struct map_session_data *)bl))
-		return 0;
+	if(bl->type == BL_PC) {
+		if (pc_isdead((struct map_session_data *)bl))
+			return 0;
+		else if (pc_ishiding((struct map_session_data *)bl))
+			return 0;
+	}
 
 	// 同じmapでないなら攻?しない
 	// PCが死んでても攻?しない
@@ -4685,7 +4762,7 @@ int pc_attack_timer(int tid,unsigned int tick,int id,int data)
 			return 0;
 		if(sd->sc_data[SC_BLADESTOP].timer != -1)
 			return 0;
-	}	
+	}
 
 	//if((opt = battle_get_option(bl)) != NULL && *opt&0x46)
 	if((opt = battle_get_option(bl)) != NULL && *opt&0x42)
@@ -4774,13 +4851,13 @@ int pc_attack(struct map_session_data *sd,int target_id,int type)
 		return 1;
 
 	sd->idletime = tick_;
-	
+
 	if(bl->type==BL_NPC) { // monster npcs [Valaris]
 		//npc_click(sd,RFIFOL(sd->fd,2));
 		npc_click(sd,target_id); // submitted by leinsirk10 [Celest]
 		return 0;
 	}
-	
+
 	if(!battle_check_target(&sd->bl,bl,BCT_ENEMY))
 		return 1;
 	if(sd->attacktimer != -1)
@@ -4972,7 +5049,7 @@ int pc_gainexp(struct map_session_data *sd,int base_exp,int job_exp)
 	sd->status.base_exp += base_exp;
 	if(sd->status.base_exp < 0)
 		sd->status.base_exp = 0;
-	
+
 	while(pc_checkbaselevelup(sd)) ;
 
 	clif_updatestatus(sd,SP_BASEEXP);
@@ -4985,13 +5062,13 @@ int pc_gainexp(struct map_session_data *sd,int base_exp,int job_exp)
 	sd->status.job_exp += job_exp;
 	if(sd->status.job_exp < 0)
 		sd->status.job_exp = 0;
-	
+
 	while(pc_checkjoblevelup(sd)) ;
 
 	clif_updatestatus(sd,SP_JOBEXP);
 
 	if(battle_config.disp_experience){
-		sprintf(output, 
+		sprintf(output,
 			"Experienced Gained Base:%d Job:%d",base_exp,job_exp);
 		clif_disp_onlyself(sd,output,strlen(output));
 	}
@@ -5124,7 +5201,7 @@ int pc_need_status_point(struct map_session_data *sd,int type)
 int pc_statusup(struct map_session_data *sd,int type)
 {
 	int max, need,val = 0;
-		
+
 	nullpo_retr(0, sd);
 
 	max = (pc_calc_upper(sd->status.class_)==2) ? 80 : battle_config.max_parameter;
@@ -5326,17 +5403,21 @@ int pc_allskillup(struct map_session_data *sd)
 			sd->status.skill[i].lv=skill_get_max(i);
 		for(i=210;i<291;i++)
 			sd->status.skill[i].lv=skill_get_max(i);
-		for(i=304;i<MAX_SKILL;i++){
+		for(i=304;i<338;i++){
 			if(i==331) continue;
 			sd->status.skill[i].lv=skill_get_max(i);
 		}
+		if(battle_config.enable_upper_class){ //confで無?でなければ?み?む
+			for(i=355;i<411;i++)
+				sd->status.skill[i].id=i;
+		}
 	}
 	else {
 		for(i=0;(id=skill_tree[s][c][i].id)>0;i++){
 			if(sd->status.skill[id].id==0 && (!(skill_get_inf2(id)&0x01) || battle_config.quest_skill_learn) ) {
 				sd->status.skill[id].id = id;	// celest
 				// sd->status.skill[id].lv=skill_get_max(id);
-				sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_);	// celest				
+				sd->status.skill[id].lv = skill_tree_get_max(id, sd->status.class_);	// celest
 			}
 		}
 	}
@@ -5352,9 +5433,9 @@ int pc_allskillup(struct map_session_data *sd)
 int pc_resetlvl(struct map_session_data* sd,int type)
 {
 	int  i;
-	
+
 	nullpo_retr(0, sd);
-	
+
 	for(i=1;i<MAX_SKILL;i++){
 		sd->status.skill[i].lv = 0;
 	}
@@ -5395,7 +5476,7 @@ int pc_resetlvl(struct map_session_data* sd,int type)
 	if(type == 4){
 		sd->status.job_level=1;
 		sd->status.job_exp=0;
-	}	
+	}
 
 	clif_updatestatus(sd,SP_STATUSPOINT);
 	clif_updatestatus(sd,SP_STR);
@@ -5444,7 +5525,7 @@ int pc_resetstate(struct map_session_data* sd)
 	sd->status.status_point = atoi (statp[sd->status.base_level - 1]);
 	if(sd->status.class_ >= 4001 && sd->status.class_ <= 4024)
 		sd->status.status_point+=52;	// extra 52+48=100 stat points
-//	End addition 
+//	End addition
 
 //	Removed by Dexity - old count
 //	add += sumsp(sd->status.str);
@@ -5794,7 +5875,7 @@ int pc_readparam(struct map_session_data *sd,int type)
 {
 	int val=0;
 	struct pc_base_job s_class;
-	
+
 	s_class = pc_calc_base_job(sd->status.class_);
 
 	nullpo_retr(0, sd);
@@ -6208,12 +6289,12 @@ int pc_jobchange(struct map_session_data *sd,int job, int upper)
 	int b_class = 0;
 	//?生や養子の場合の元の職業を算出する
 	struct pc_base_job s_class = pc_calc_base_job(sd->status.class_);
-	
+
 	nullpo_retr(0, sd);
 
 	if (upper < 0 || upper > 2) //現在?生かどうかを判?する
 		upper = s_class.upper;
-	
+
 	b_class = job;	//通常職ならjobそのまんま
 	if (job < 23) {
 		if (upper == 1)
@@ -6248,8 +6329,8 @@ int pc_jobchange(struct map_session_data *sd,int job, int upper)
  	else
  		sd->change_level = 0;
 
-	pc_setglobalreg (sd, "jobchange_level", sd->change_level);		
-	
+	pc_setglobalreg (sd, "jobchange_level", sd->change_level);
+
 	sd->status.class_ = sd->view_class = b_class;
 
 	sd->status.job_level=1;
@@ -6276,12 +6357,12 @@ int pc_jobchange(struct map_session_data *sd,int job, int upper)
 	clif_equiplist(sd);
 
 	if(pc_isriding(sd)) {	// remove peco status if changing into invalid class [Valaris]
-		if(!(pc_checkskill(sd,KN_RIDING))) 
+		if(!(pc_checkskill(sd,KN_RIDING)))
 			pc_setoption(sd,sd->status.option|-0x0000);
 		if(pc_checkskill(sd,KN_RIDING)>0)
 			 pc_setriding(sd);
 	}
-	
+
 	return 0;
 }
 
@@ -6418,13 +6499,13 @@ int pc_setriding(struct map_session_data *sd)
 
 		if(sd->status.class_==7)
 			sd->status.class_=sd->view_class=13;
-		
+
 		if(sd->status.class_==14)
 			sd->status.class_=sd->view_class=21;
-		
+
 		if(sd->status.class_==4008)
 			sd->status.class_=sd->view_class=4014;
-		
+
 		if(sd->status.class_==4015)
 			sd->status.class_=sd->view_class=4022;
 	}
@@ -6772,7 +6853,7 @@ int pc_eventtimer(int tid,unsigned int tick,int id,int data)
 			break;
 		}
 	}
-	free((void *)data);
+	aFree((void *)data);
 	if(i==MAX_EVENTTIMER) {
 		if(battle_config.error_log)
 			printf("pc_eventtimer: no such event timer\n");
@@ -6795,7 +6876,7 @@ int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
 		if( sd->eventtimer[i]==-1 )
 			break;
 	if(i<MAX_EVENTTIMER){
-		char *evname=(char *)aMalloc((strlen(name)+1)*sizeof(char));
+		char *evname=(char *)aMallocA((strlen(name)+1)*sizeof(char));
 		memcpy(evname,name,(strlen(name)+1));
 		sd->eventtimer[i]=add_timer(gettick()+tick,
 			pc_eventtimer,sd->bl.id,(int)evname);
@@ -7035,7 +7116,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int pos)
  */
 int pc_unequipitem(struct map_session_data *sd,int n,int flag)
 {
-	nullpo_retr(0, sd);	
+	nullpo_retr(0, sd);
 
 // -- moonsoul	(if player is berserk then cannot unequip)
 //
@@ -7243,7 +7324,7 @@ int pc_calc_pvprank(struct map_session_data *sd)
 
 	nullpo_retr(0, sd);
 	nullpo_retr(0, m=&map[sd->bl.m]);
-	
+
 	old=sd->pvp_rank;
 
 	if( !(m->flag.pvp) )
@@ -7385,8 +7466,8 @@ static int pc_spheal(struct map_session_data *sd)
 	if(gc)	{
 		struct guild *g;
 		g=guild_search(sd->status.guild_id);
-		if(g && g->guild_id == gc->guild_id) 
-			a += a;	
+		if(g && g->guild_id == gc->guild_id)
+			a += a;
 	}	// end addition [Valaris]
 
 	return a;
@@ -7415,8 +7496,8 @@ static int pc_hpheal(struct map_session_data *sd)
 	if(gc)	{
 		struct guild *g;
 		g=guild_search(sd->status.guild_id);
-		if(g && g->guild_id == gc->guild_id) 
-			a += a;	
+		if(g && g->guild_id == gc->guild_id)
+			a += a;
 	}	// end addition [Valaris]
 
 	return a;
@@ -7680,8 +7761,8 @@ static int pc_natural_heal_sub(struct map_session_data *sd,va_list ap) {
 
 // -- moonsoul (if conditions below altered to disallow natural healing if under berserk status)
 	if ((battle_config.natural_heal_weight_rate > 100 || sd->weight*100/sd->max_weight < battle_config.natural_heal_weight_rate) &&
-		!pc_isdead(sd) && 
-		!pc_ishiding(sd) && 
+		!pc_isdead(sd) &&
+		!pc_ishiding(sd) &&
 	//-- cannot regen for 5 minutes after using Berserk --- [Celest]
 		DIFF_TICK (gettick(), sd->canregen_tick)>=0 &&
 		(sd->sc_data && !(sd->sc_data[SC_POISON].timer != -1 && sd->sc_data[SC_SLOWPOISON].timer == -1) &&
@@ -7746,7 +7827,7 @@ static int pc_autosave_sub(struct map_session_data *sd,va_list ap)
 {
 	nullpo_retr(0, sd);
 
-	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd);
 
 	if(save_flag==0 && sd->fd>last_save_fd){
 		struct guild_castle *gc=NULL;
@@ -7807,10 +7888,10 @@ int pc_read_gm_account(int fd)
         int i = 0;
 #endif
 	if (gm_account != NULL)
-		free(gm_account);
+		aFree(gm_account);
 	GM_num = 0;
 #ifdef TXT_ONLY
-	gm_account = aCalloc(sizeof(struct gm_account) * ((RFIFOW(fd,2) - 4) / 5), 1);
+	gm_account = aCallocA(sizeof(struct gm_account) * ((RFIFOW(fd,2) - 4) / 5), 1);
 	for (i = 4; i < RFIFOW(fd,2); i = i + 5) {
 		gm_account[GM_num].account_id = RFIFOL(fd,i);
 		gm_account[GM_num].level = (int)RFIFOB(fd,i+4);
@@ -7824,7 +7905,7 @@ int pc_read_gm_account(int fd)
 	}
 	lsql_res = mysql_store_result(&lmysql_handle);
 	if (lsql_res) {
-	    gm_account = aCalloc(sizeof(struct gm_account) * mysql_num_rows(lsql_res), 1);
+	    gm_account = aCallocA(sizeof(struct gm_account) * mysql_num_rows(lsql_res), 1);
 	    while ((lsql_row = mysql_fetch_row(lsql_res))) {
 	        gm_account[GM_num].account_id = atoi(lsql_row[0]);
 		    gm_account[GM_num].level = atoi(lsql_row[1]);
@@ -7832,7 +7913,7 @@ int pc_read_gm_account(int fd)
 		    GM_num++;
 	    }
     }
-	
+
     mysql_free_result(lsql_res);
 #endif /* TXT_ONLY */
 	return GM_num;
@@ -7926,7 +8007,7 @@ int pc_readdb(void)
 	char line[1024],*p;
 
 	// 必要??値?み?み
-
+	memset(exp_table,0,sizeof(exp_table));
 	fp=fopen("db/exp.txt","r");
 	if(fp==NULL){
 		printf("can't read db/exp.txt\n");
@@ -7997,6 +8078,7 @@ int pc_readdb(void)
 	ShowStatus(tmp_output);
 
 	// JOBボ?ナス
+	memset(job_bonus,0,sizeof(job_bonus));
 	fp=fopen("db/job_db2.txt","r");
 	if(fp==NULL){
 		printf("can't read db/job_db2.txt\n");
@@ -8076,7 +8158,7 @@ int pc_readdb(void)
 		for(j=0;skill_tree[u][i][j].id;j++);
 		skill_tree[u][i][j].id=atoi(split[1]);
 		skill_tree[u][i][j].max=atoi(split[2]);
-		
+
 		//not required - Celest
 		//skill_tree[2][i][j].id=atoi(split[1]); //養子職は良く分からないので暫定
 		//skill_tree[2][i][j].max=atoi(split[2]); //養子職は良く分からないので暫定
@@ -8242,7 +8324,7 @@ static void pc_statpointdb(void)
         end = ftell(stp);
         rewind(stp);
 
-	buf_stat = (char *) malloc (end + 1);
+	buf_stat = (char *) aMallocA (end + 1);
 	l = fread(buf_stat,1,end,stp);
 	fclose(stp);
 	sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","db/statpoint.txt");
@@ -8251,7 +8333,7 @@ static void pc_statpointdb(void)
 
 	for(i=0;i<255;i++) {
             j=0;
-            while (*(buf_stat+k)!='\n') { 
+            while (*(buf_stat+k)!='\n') {
                     statp[i][j]=*(buf_stat+k);
                     j++;k++;
                 }
@@ -8259,7 +8341,7 @@ static void pc_statpointdb(void)
             k++;
 	}
 
-        free(buf_stat);
+        aFree(buf_stat);
 }
 
 /*==========================================

+ 2 - 2
src/map/pet.c

@@ -1376,7 +1376,7 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
 						clif_additem(sd,0,0,flag);
 						map_addflooritem(&ditem->item_data,ditem->item_data.amount,ditem->m,ditem->x,ditem->y,ditem->first_sd,ditem->second_sd,ditem->third_sd,0);
 					}
-					free(ditem);
+					aFree(ditem);
 				}
 				else
 					add_timer(gettick()+540+i,pet_delay_item_drop2,(int)ditem,0);
@@ -1399,7 +1399,7 @@ int pet_delay_item_drop2(int tid,unsigned int tick,int id,int data)
 
 	map_addflooritem(&ditem->item_data,ditem->item_data.amount,ditem->m,ditem->x,ditem->y,ditem->first_sd,ditem->second_sd,ditem->third_sd,0);
 
-	free(ditem);
+	aFree(ditem);
 	return 0;
 }
 

+ 122 - 118
src/map/script.c

@@ -507,7 +507,7 @@ struct {
 	{buildin_npctalk,"npctalk","*"}, // [Valaris]
 	{buildin_hasitems,"hasitems","*"}, // [Valaris]
 	{buildin_mobcount,"mobcount","ss"},
-	{buildin_getlook,"getlook","i"},                
+	{buildin_getlook,"getlook","i"},
 	{buildin_getsavepoint,"getsavepoint","i"},
 	{buildin_npcspeed,"npcspeed","i"}, // [Valaris]
 	{buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
@@ -576,14 +576,14 @@ static int add_str(const unsigned char *p)
 	int i;
 	char *lowcase;
 
-	lowcase=strdup(p);
+	lowcase=aStrdup(p);
 	for(i=0;lowcase[i];i++)
 		lowcase[i]=tolower(lowcase[i]);
 	if((i=search_str(lowcase))>=0){
-		free(lowcase);
+		aFree(lowcase);
 		return i;
 	}
-	free(lowcase);
+	aFree(lowcase);
 
 	i=calc_hash(p);
 	if(str_hash[i]==0){
@@ -605,7 +605,7 @@ static int add_str(const unsigned char *p)
 		str_data=aRealloc(str_data,sizeof(str_data[0])*str_data_size);
 		memset(str_data + (str_data_size - 128), '\0', 128);
 	}
-	while(str_pos+strlen(p)+1>=str_size){
+	while(str_pos+(int)strlen(p)+1>=str_size){
 		str_size+=256;
 		str_buf=(char *)aRealloc(str_buf,str_size);
 		memset(str_buf + (str_size - 256), '\0', 256);
@@ -1159,7 +1159,7 @@ unsigned char* parse_script(unsigned char *src,int line)
 		read_constdb();
 	}
 	first=0;
-	script_buf=(unsigned char *)aCalloc(SCRIPT_BLOCK_SIZE,sizeof(unsigned char));
+	script_buf=(unsigned char *)aCallocA(SCRIPT_BLOCK_SIZE,sizeof(unsigned char));
 	script_pos=0;
 	script_size=SCRIPT_BLOCK_SIZE;
 	str_data[LABEL_NEXTLINE].type=C_NOP;
@@ -1395,7 +1395,7 @@ char* conv_str(struct script_state *st,struct script_data *data)
 	get_val(st,data);
 	if(data->type==C_INT){
 		char *buf;
-		buf=(char *)aCalloc(16,sizeof(char));
+		buf=(char *)aCallocA(16,sizeof(char));
 		sprintf(buf,"%d",data->u.num);
 		data->type=C_STR;
 		data->u.str=buf;
@@ -1421,7 +1421,7 @@ int conv_num(struct script_state *st,struct script_data *data)
 		p=data->u.str;
 		data->u.num = atoi(p);
 		if(data->type==C_STR)
-			free(p);
+			aFree(p);
 		data->type=C_INT;
 	}
 	return data->u.num;
@@ -1478,7 +1478,7 @@ void push_copy(struct script_stack *stack,int pos)
 		push_str(stack,C_CONSTSTR,stack->stack_data[pos].u.str);
 		break;
 	case C_STR:
-		push_str(stack,C_STR,strdup(stack->stack_data[pos].u.str));
+		push_str(stack,C_STR,aStrdup(stack->stack_data[pos].u.str));
 		break;
 	default:
 		push_val(stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num);
@@ -1495,7 +1495,7 @@ void pop_stack(struct script_stack* stack,int start,int end)
 	int i;
 	for(i=start;i<end;i++){
 		if(stack->stack_data[i].type==C_STR){
-			free(stack->stack_data[i].u.str);
+			aFree(stack->stack_data[i].u.str);
 		}
 	}
 	if(stack->sp>end){
@@ -1663,7 +1663,7 @@ int buildin_menu(struct script_state *st)
 	char *buf;
 	int len,i;
 	struct map_session_data *sd;
-	
+
 	sd=script_rid2sd(st);
 
 	if(sd->state.menu_or_input==0){
@@ -1673,14 +1673,14 @@ int buildin_menu(struct script_state *st)
 			conv_str(st,& (st->stack->stack_data[i]));
 			len+=strlen(st->stack->stack_data[i].u.str)+1;
 		}
-		buf=(char *)aCalloc(len,sizeof(char));
+		buf=(char *)aCallocA(len,sizeof(char));
 		buf[0]=0;
 		for(i=st->start+2,len=0;i<st->end;i+=2){
 			strcat(buf,st->stack->stack_data[i].u.str);
 			strcat(buf,":");
 		}
 		clif_scriptmenu(script_rid2sd(st),st->oid,buf);
-		free(buf);
+		aFree(buf);
 	} else if(sd->npc_menu==0xff){	// cansel
 		sd->state.menu_or_input=0;
 		st->state=END;
@@ -2522,7 +2522,7 @@ int buildin_delitem(struct script_state *st)
 		if(sd->inventory_data[i]->type==7 && sd->status.inventory[i].card[0] == (short)0xff00 && search_petDB_index(nameid, PET_EGG) >= 0 ){
 			intif_delete_petdata(*((long *)(&sd->status.inventory[i].card[1])));
 			//clear egg flag. so it won't be put in IMPORTANT items (eggs look like item with 2 cards ^_^)
-			sd->status.inventory[i].card[1] = sd->status.inventory[i].card[0] = 0; 
+			sd->status.inventory[i].card[1] = sd->status.inventory[i].card[0] = 0;
 			//now this egg'll be deleted as a common unimportant item
 		}
 		//is this item important? does it have cards? or Player's name? or Refined/Upgraded
@@ -2551,7 +2551,7 @@ int buildin_delitem(struct script_state *st)
 				continue;
 
 			if(sd->status.inventory[i].amount>=amount){
-				pc_delitem(sd,i,amount,0);		
+				pc_delitem(sd,i,amount,0);
 				return 0; //we deleted exact amount of items. now exit
 			} else {
 				amount-=sd->status.inventory[i].amount;
@@ -2627,7 +2627,7 @@ char *buildin_getpartyname_sub(int party_id)
 
 	if(p!=NULL){
 		char *buf;
-		buf=(char *)aCalloc(24,sizeof(char));
+		buf=(char *)aCallocA(24,sizeof(char));
 		strcpy(buf,p->name);
 		return buf;
 	}
@@ -2684,7 +2684,7 @@ char *buildin_getguildname_sub(int guild_id)
 
 	if(g!=NULL){
 		char *buf;
-		buf=(char *)aCalloc(24,sizeof(char));
+		buf=(char *)aCallocA(24,sizeof(char));
 		strcpy(buf,g->name);
 		return buf;
 	}
@@ -2713,7 +2713,7 @@ char *buildin_getguildmaster_sub(int guild_id)
 
 	if(g!=NULL){
 		char *buf;
-		buf=(char *)aCalloc(24,sizeof(char));
+		buf=(char *)aCallocA(24,sizeof(char));
 		strncpy(buf,g->master, 23);
 		return buf;
 	}
@@ -2763,7 +2763,7 @@ int buildin_strcharinfo(struct script_state *st)
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	if(num==0){
 		char *buf;
-		buf=(char *)aCalloc(24,sizeof(char));
+		buf=(char *)aCallocA(24,sizeof(char));
 		strncpy(buf,sd->status.name, 23);
 		push_str(st->stack,C_STR,buf);
 	}
@@ -2830,7 +2830,7 @@ int buildin_getequipname(struct script_state *st)
 	struct item_data* item;
 	char *buf;
 
-	buf=(char *)aCalloc(64,sizeof(char));
+	buf=(char *)aCallocA(64,sizeof(char));
 	sd=script_rid2sd(st);
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	i=pc_checkequip(sd,equip[num-1]);
@@ -2856,9 +2856,9 @@ int buildin_getbrokenid(struct script_state *st)
 {
 	int i,num,id=0,brokencounter=0;
 	struct map_session_data *sd;
-	
+
 	sd=script_rid2sd(st);
-	
+
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	for(i=0; i<MAX_INVENTORY; i++) {
 		if(sd->status.inventory[i].attribute==1){
@@ -2869,7 +2869,7 @@ int buildin_getbrokenid(struct script_state *st)
 				}
 		}
 	}
-	
+
 	push_val(st->stack,C_INT,id);
 
 	return 0;
@@ -2887,7 +2887,7 @@ int buildin_repair(struct script_state *st)
 
 
 	sd=script_rid2sd(st);
-	
+
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	for(i=0; i<MAX_INVENTORY; i++) {
 		if(sd->status.inventory[i].attribute==1){
@@ -2941,7 +2941,7 @@ int buildin_getequipisenableref(struct script_state *st)
 	i=pc_checkequip(sd,equip[num-1]);
 	if(i >= 0 && num<7 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
 			// replaced by Celest
-			/*(num!=1 
+			/*(num!=1
 				 || sd->inventory_data[i]->def > 1
 	             || (sd->inventory_data[i]->def==1 && sd->inventory_data[i]->equip_script==NULL)
 	             || (sd->inventory_data[i]->def<=0 && sd->inventory_data[i]->equip_script!=NULL)))*/
@@ -3245,15 +3245,15 @@ int buildin_getskilllv(struct script_state *st)
 	return 0;
 }
 /*==========================================
- * getgdskilllv(Guild_ID, Skill_ID);               
- * skill_id = 10000 : GD_APPROVAL                      
- *            10001 : GD_KAFRACONTACT                  
- *            10002 : GD_GUARDIANRESEARCH              
- *            10003 : GD_GUARDUP                      
- *            10004 : GD_EXTENSION                     
+ * getgdskilllv(Guild_ID, Skill_ID);
+ * skill_id = 10000 : GD_APPROVAL
+ *            10001 : GD_KAFRACONTACT
+ *            10002 : GD_GUARDIANRESEARCH
+ *            10003 : GD_GUARDUP
+ *            10004 : GD_EXTENSION
  *------------------------------------------
  */
-int buildin_getgdskilllv(struct script_state *st)  
+int buildin_getgdskilllv(struct script_state *st)
 {
         int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
         int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
@@ -3590,7 +3590,7 @@ int buildin_gettimestr(struct script_state *st)
 	fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
 	maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
 
-	tmpstr=(char *)aCalloc(maxlen+1,sizeof(char));
+	tmpstr=(char *)aCallocA(maxlen+1,sizeof(char));
 	strftime(tmpstr,maxlen,fmtstr,localtime(&now));
 	tmpstr[maxlen]='\0';
 
@@ -3677,8 +3677,8 @@ int buildin_makepet(struct script_state *st)
 		sd->catch_target_class = pet_db[pet_id].class_;
 		intif_create_pet(
 			sd->status.account_id, sd->status.char_id,
-			pet_db[pet_id].class_, mob_db[pet_db[pet_id].class_].lv,
-			pet_db[pet_id].EggID, 0, pet_db[pet_id].intimate,
+			(short)pet_db[pet_id].class_, (short)mob_db[pet_db[pet_id].class_].lv,
+			(short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
 			100, 0, 1, pet_db[pet_id].jname);
 	}
 
@@ -3727,19 +3727,19 @@ int buildin_guildgetexp(struct script_state *st)
  */
 int buildin_monster(struct script_state *st)
 {
-	int class,amount,x,y;
+	int class_,amount,x,y;
 	char *str,*map,*event="";
 
 	map	=conv_str(st,& (st->stack->stack_data[st->start+2]));
 	x	=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	y	=conv_num(st,& (st->stack->stack_data[st->start+4]));
 	str	=conv_str(st,& (st->stack->stack_data[st->start+5]));
-	class=conv_num(st,& (st->stack->stack_data[st->start+6]));
+	class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
 	amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
 	if( st->end>st->start+8 )
 		event=conv_str(st,& (st->stack->stack_data[st->start+8]));
 
-	mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class,amount,event);
+	mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
 	return 0;
 }
 /*==========================================
@@ -3748,7 +3748,7 @@ int buildin_monster(struct script_state *st)
  */
 int buildin_areamonster(struct script_state *st)
 {
-	int class,amount,x0,y0,x1,y1;
+	int class_,amount,x0,y0,x1,y1;
 	char *str,*map,*event="";
 
 	map	=conv_str(st,& (st->stack->stack_data[st->start+2]));
@@ -3757,12 +3757,12 @@ int buildin_areamonster(struct script_state *st)
 	x1	=conv_num(st,& (st->stack->stack_data[st->start+5]));
 	y1	=conv_num(st,& (st->stack->stack_data[st->start+6]));
 	str	=conv_str(st,& (st->stack->stack_data[st->start+7]));
-	class=conv_num(st,& (st->stack->stack_data[st->start+8]));
+	class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
 	amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
 	if( st->end>st->start+10 )
 		event=conv_str(st,& (st->stack->stack_data[st->start+10]));
 
-	mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class,amount,event);
+	mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
 	return 0;
 }
 /*==========================================
@@ -3974,7 +3974,7 @@ int buildin_attachnpctimer(struct script_state *st)
 	struct map_session_data *sd;
 	struct npc_data *nd;
 
-	nd=(struct npc_data *)map_id2bl(st->oid);	
+	nd=(struct npc_data *)map_id2bl(st->oid);
 	if( st->end > st->start+2 ) {
 		char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
 		sd=map_nick2sd(name);
@@ -4270,7 +4270,7 @@ int buildin_sc_start(struct script_state *st)
 		bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
 	else
 	bl = map_id2bl(st->rid);
-	
+
 	if (bl != 0) {
 		if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
 			bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
@@ -5101,7 +5101,7 @@ int buildin_getcastlename(struct script_state *st)
 	for(i=0;i<MAX_GUILDCASTLE;i++){
 		if( (gc=guild_castle_search(i)) != NULL ){
 			if(strcmp(mapname,gc->map_name)==0){
-				buf=(char *)aCalloc(24,sizeof(char));
+				buf=(char *)aCallocA(24,sizeof(char));
 				strncpy(buf,gc->castle_name,24);
 				break;
 			}
@@ -5343,8 +5343,8 @@ int buildin_failedremovecards(struct script_state *st)
 		if( (sd->status.inventory[i].card[c-1] > 4000 &&
 			sd->status.inventory[i].card[c-1] < 5000) ||
 			itemdb_type(sd->status.inventory[i].card[c-1]) == 6){	// [Celest]
-			 
-			cardflag = 1; 
+
+			cardflag = 1;
 
 			if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
 				item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
@@ -5561,39 +5561,39 @@ int buildin_strmobinfo(struct script_state *st)
 {
 
 	int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
-	int class=conv_num(st,& (st->stack->stack_data[st->start+3]));
+	int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
 
-	if(num<=0 || num>=8 || (class>=0 && class<=1000) || class >2000)
+	if(num<=0 || num>=8 || (class_>=0 && class_<=1000) || class_ >2000)
 		return 0;
 
 	if(num==1) {
 		char *buf;
-		buf=aCalloc(24, 1);
-//		buf=mob_db[class].name;
+		buf=aCallocA(24, 1);
+//		buf=mob_db[class_].name;
 // for string assignments you would need to go for c++ [Shinomori]
-		strcpy(buf,mob_db[class].name);
+		strcpy(buf,mob_db[class_].name);
 		push_str(st->stack,C_STR,buf);
 		return 0;
 	}
 	else if(num==2)	{
 		char *buf;
-		buf=aCalloc(24, 1);
-//		buf=mob_db[class].jname;
+		buf=aCallocA(24, 1);
+//		buf=mob_db[class_].jname;
 // for string assignments you would need to go for c++ [Shinomori]
-		strcpy(buf,mob_db[class].jname);
+		strcpy(buf,mob_db[class_].jname);
 		push_str(st->stack,C_STR,buf);
 		return 0;
 	}
 	else if(num==3)
-		push_val(st->stack,C_INT,mob_db[class].lv);
+		push_val(st->stack,C_INT,mob_db[class_].lv);
 	else if(num==4)
-		push_val(st->stack,C_INT,mob_db[class].max_hp);
+		push_val(st->stack,C_INT,mob_db[class_].max_hp);
 	else if(num==5)
-		push_val(st->stack,C_INT,mob_db[class].max_sp);
+		push_val(st->stack,C_INT,mob_db[class_].max_sp);
 	else if(num==6)
-		push_val(st->stack,C_INT,mob_db[class].base_exp);
+		push_val(st->stack,C_INT,mob_db[class_].base_exp);
 	else if(num==7)
-		push_val(st->stack,C_INT,mob_db[class].job_exp);
+		push_val(st->stack,C_INT,mob_db[class_].job_exp);
 	return 0;
 }
 
@@ -5603,20 +5603,20 @@ int buildin_strmobinfo(struct script_state *st)
  */
 int buildin_guardian(struct script_state *st)
 {
-	int class=0,amount=1,x=0,y=0,guardian=0;
+	int class_=0,amount=1,x=0,y=0,guardian=0;
 	char *str,*map,*event="";
 
 	map	=conv_str(st,& (st->stack->stack_data[st->start+2]));
 	x	=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	y	=conv_num(st,& (st->stack->stack_data[st->start+4]));
 	str	=conv_str(st,& (st->stack->stack_data[st->start+5]));
-	class=conv_num(st,& (st->stack->stack_data[st->start+6]));
+	class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
 	amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
 	event=conv_str(st,& (st->stack->stack_data[st->start+8]));
 	if( st->end>st->start+9 )
 		guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
 
-	mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class,amount,event,guardian);
+	mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
 
 	return 0;
 }
@@ -5657,7 +5657,7 @@ int buildin_getitemname(struct script_state *st)
 
 	i_data = NULL;
 	i_data = itemdb_search(item_id);
-	item_name=(char *)aCalloc(24,sizeof(char));
+	item_name=(char *)aCallocA(24,sizeof(char));
 
 	strncpy(item_name,i_data->jname,23);
 	push_str(st->stack,C_STR,item_name);
@@ -5671,12 +5671,12 @@ int buildin_getitemname(struct script_state *st)
 
 int buildin_petskillbonus(struct script_state *st)
 {
-	int type,val,duration,timer; 
+	int type,val,duration,timer;
 	struct pet_data *pd;
 
-	struct map_session_data *sd=script_rid2sd(st);	
+	struct map_session_data *sd=script_rid2sd(st);
 
-	if(sd==NULL || sd->pd==NULL) 
+	if(sd==NULL || sd->pd==NULL)
 		return 0;
 
 	pd=sd->pd;
@@ -5691,7 +5691,7 @@ int buildin_petskillbonus(struct script_state *st)
 
 	pd->skillbonusduration=-1;
 	pd->skillbonustimer=-1;
-		
+
 	pet_skill_bonus(sd,pd,type,val,duration,timer,0);
 
 	return 0;
@@ -5719,7 +5719,7 @@ int buildin_petloot(struct script_state *st)
 
 	if(!max)
 		return 0;
-	
+
 	pd->loot=1;
 	pd->lootmax=max;
 
@@ -5790,14 +5790,14 @@ int buildin_clearitem(struct script_state *st)
  */
 int buildin_classchange(struct script_state *st)
 {
-	int class,type;
+	int _class,type;
 	struct block_list *bl=map_id2bl(st->oid);
-	
+
 	if(bl==NULL) return 0;
 
-	class=conv_num(st,& (st->stack->stack_data[st->start+2]));
+	_class=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	type=conv_num(st,& (st->stack->stack_data[st->start+3]));
-	clif_class_change(bl,class,type);
+	clif_class_change(bl,_class,type);
 	return 0;
 }
 
@@ -5867,9 +5867,9 @@ int buildin_petrecovery(struct script_state *st)
 {
 	struct pet_data *pd;
 
-	struct map_session_data *sd=script_rid2sd(st);	
+	struct map_session_data *sd=script_rid2sd(st);
 
-	if(sd==NULL || sd->pd==NULL) 
+	if(sd==NULL || sd->pd==NULL)
 		return 0;
 
 	pd=sd->pd;
@@ -5893,9 +5893,9 @@ int buildin_petheal(struct script_state *st)
 
 {
 	struct pet_data *pd;
-	struct map_session_data *sd=script_rid2sd(st);	
+	struct map_session_data *sd=script_rid2sd(st);
 
-	if(sd==NULL || sd->pd==NULL) 
+	if(sd==NULL || sd->pd==NULL)
 		return 0;
 
 	pd=sd->pd;
@@ -5911,7 +5911,7 @@ int buildin_petheal(struct script_state *st)
 
 	return 0;
 }
-	
+
 /*==========================================
  * pet magnificat [Valaris]
  *------------------------------------------
@@ -5919,9 +5919,9 @@ int buildin_petheal(struct script_state *st)
 int buildin_petmag(struct script_state *st)
 {
 	struct pet_data *pd;
-	struct map_session_data *sd=script_rid2sd(st);	
+	struct map_session_data *sd=script_rid2sd(st);
 
-	if(sd==NULL || sd->pd==NULL) 
+	if(sd==NULL || sd->pd==NULL)
 		return 0;
 
 	pd=sd->pd;
@@ -5946,9 +5946,9 @@ int buildin_petmag(struct script_state *st)
 int buildin_petskillattack(struct script_state *st)
 {
 	struct pet_data *pd;
-	struct map_session_data *sd=script_rid2sd(st);	
+	struct map_session_data *sd=script_rid2sd(st);
 
-	if(sd==NULL || sd->pd==NULL) 
+	if(sd==NULL || sd->pd==NULL)
 		return 0;
 
 	pd=sd->pd;
@@ -5957,7 +5957,7 @@ int buildin_petskillattack(struct script_state *st)
 		return 0;
 
 	pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
-	pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+3]));	
+	pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	pd->skillduration=conv_num(st,& (st->stack->stack_data[st->start+4]));
 	pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+5]));
 
@@ -5973,11 +5973,11 @@ int buildin_petskillattack(struct script_state *st)
 int buildin_skilleffect(struct script_state *st)
 {
 	struct map_session_data *sd;
-	
+
 	int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	sd=script_rid2sd(st);
-	
+
 	clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
 
 	return 0;
@@ -5990,9 +5990,9 @@ int buildin_skilleffect(struct script_state *st)
 int buildin_npcskilleffect(struct script_state *st)
 {
 	struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
-	
+
 	int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
-	int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));	
+	int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
 	int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
 
@@ -6036,13 +6036,13 @@ int buildin_specialeffect2(struct script_state *st)
 
 int buildin_nude(struct script_state *st)
 {
-	struct map_session_data *sd=script_rid2sd(st);	
+	struct map_session_data *sd=script_rid2sd(st);
 	int i;
 
 	if(sd==NULL)
 		return 0;
-	
-	for(i=0;i<11;i++) 
+
+	for(i=0;i<11;i++)
 		if(sd->equip_index[i] >= 0)
 			pc_unequipitem(sd,sd->equip_index[i],2);
 
@@ -6118,7 +6118,7 @@ int buildin_message(struct script_state *st)
  * area) [Valaris]
  *------------------------------------------
  */
- 
+
 int buildin_npctalk(struct script_state *st)
 {
 	char *str;
@@ -6148,16 +6148,16 @@ int buildin_hasitems(struct script_state *st)
 {
 	int i;
 	struct map_session_data *sd;
-	
+
 	sd=script_rid2sd(st);
-	
+
 	for(i=0; i<MAX_INVENTORY; i++) {
 		if(sd->status.inventory[i].amount) {
 			push_val(st->stack,C_INT,1);
 			return 0;
 		}
 	}
-	
+
 	push_val(st->stack,C_INT,0);
 
 	return 0;
@@ -6262,7 +6262,7 @@ int buildin_getsavepoint(struct script_state *st)
         sd=script_rid2sd(st);
 
         type=conv_num(st,& (st->stack->stack_data[st->start+2]));
-        mapname=aCalloc(24, 1);
+        mapname=aCallocA(24, 1);
 
         x=sd->status.save_point.x;
         y=sd->status.save_point.y;
@@ -6331,7 +6331,7 @@ int buildin_getmapxy(struct script_state *st){
 
 //??????????? >>>  Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
 	type=conv_num(st,& (st->stack->stack_data[st->start+5]));
-	mapname=aCalloc(24, 1);
+	mapname=aCallocA(24, 1);
 
         switch (type){
             case 0:                                             //Get Character Position
@@ -6363,7 +6363,7 @@ int buildin_getmapxy(struct script_state *st){
                     }
 
                     x=nd->bl.x;
-                    y=nd->bl.y; 
+                    y=nd->bl.y;
                     strncpy(mapname,map[nd->bl.m].name,24);
                     printf(">>>>%s %d %d\n",mapname,x,y);
                     break;
@@ -6385,7 +6385,7 @@ int buildin_getmapxy(struct script_state *st){
                         return 0;
                     }
                     x=pd->bl.x;
-                    y=pd->bl.y; 
+                    y=pd->bl.y;
                     strncpy(mapname,map[pd->bl.m].name,24);
 
                     printf(">>>>%s %d %d\n",mapname,x,y);
@@ -6491,7 +6491,7 @@ int buildin_logmes(struct script_state *st)
 
 int buildin_summon(struct script_state *st)
 {
-	int class, id;
+	int _class, id;
 	char *str,*event="";
 	struct map_session_data *sd;
 	struct mob_data *md;
@@ -6500,11 +6500,11 @@ int buildin_summon(struct script_state *st)
 	if (sd) {
 		int tick = gettick();
 		str	=conv_str(st,& (st->stack->stack_data[st->start+2]));
-		class=conv_num(st,& (st->stack->stack_data[st->start+3]));
+		_class=conv_num(st,& (st->stack->stack_data[st->start+3]));
 		if( st->end>st->start+4 )
 			event=conv_str(st,& (st->stack->stack_data[st->start+4]));
 
-		id=mob_once_spawn(sd, "this", 0, 0, str,class,1,event);
+		id=mob_once_spawn(sd, "this", 0, 0, str,_class,1,event);
 		if((md=(struct mob_data *)map_id2bl(id))){
 			md->master_id=sd->bl.id;
 			md->state.special_mob_ai=1;
@@ -6608,14 +6608,14 @@ void op_add(struct script_state* st)
 		st->stack->stack_data[st->stack->sp-1].u.num += st->stack->stack_data[st->stack->sp].u.num;
 	} else { // ssの予定
 		char *buf;
-		buf=(char *)aCalloc(strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
+		buf=(char *)aCallocA(strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
 				strlen(st->stack->stack_data[st->stack->sp].u.str)+1,sizeof(char));
 		strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
 		strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
 		if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
-			free(st->stack->stack_data[st->stack->sp-1].u.str);
+			aFree(st->stack->stack_data[st->stack->sp-1].u.str);
 		if(st->stack->stack_data[st->stack->sp].type==C_STR)
-			free(st->stack->stack_data[st->stack->sp].u.str);
+			aFree(st->stack->stack_data[st->stack->sp].u.str);
 		st->stack->stack_data[st->stack->sp-1].type=C_STR;
 		st->stack->stack_data[st->stack->sp-1].u.str=buf;
 	}
@@ -6657,8 +6657,8 @@ void op_2str(struct script_state *st,int op,int sp1,int sp2)
 
 	push_val(st->stack,C_INT,a);
 
-	if(st->stack->stack_data[sp1].type==C_STR)	free(s1);
-	if(st->stack->stack_data[sp2].type==C_STR)	free(s2);
+	if(st->stack->stack_data[sp1].type==C_STR)	aFree(s1);
+	if(st->stack->stack_data[sp2].type==C_STR)	aFree(s2);
 }
 /*==========================================
  * 二項演算子(数値)
@@ -6672,7 +6672,11 @@ void op_2num(struct script_state *st,int op,int i1,int i2)
 		break;
 	case C_MUL:
 		{
+	#ifndef _MSC_VER
 		long long res = i1 * i2;
+	#else
+		__int64 res = i1 * i2;
+	#endif
 		if (res >  2147483647 )
 			i1 = 2147483647;
 		else
@@ -6988,7 +6992,7 @@ int run_script_main(unsigned char *script,int pos,int rid,int oid,struct script_
 		struct map_session_data *sd=map_id2sd(st->rid);
 		if(sd/* && sd->npc_stackbuf==NULL*/){
 			if( sd->npc_stackbuf )
-				free( sd->npc_stackbuf );
+				aFree( sd->npc_stackbuf );
 			sd->npc_stackbuf = (char *)aCalloc(sizeof(stack->stack_data[0])*stack->sp_max,sizeof(char));
 			memcpy(sd->npc_stackbuf, stack->stack_data, sizeof(stack->stack_data[0]) * stack->sp_max);
 			sd->npc_stack = stack->sp;
@@ -7022,7 +7026,7 @@ int run_script(unsigned char *script,int pos,int rid,int oid)
 		stack.sp_max=sd->npc_stackmax;
 		stack.stack_data=(struct script_data *)aCalloc(stack.sp_max,sizeof(stack.stack_data[0]));
 		memcpy(stack.stack_data,sd->npc_stackbuf,sizeof(stack.stack_data[0])*stack.sp_max);
-		free(sd->npc_stackbuf);
+		aFree(sd->npc_stackbuf);
 		sd->npc_stackbuf=NULL;
 	}else{
 		// スタック初期化
@@ -7036,7 +7040,7 @@ int run_script(unsigned char *script,int pos,int rid,int oid)
 	st.oid=oid;
 	run_script_main(script,pos,rid,oid,&st,rootscript);
 
-	free(stack.stack_data);
+	aFree(stack.stack_data);
 	stack.stack_data=NULL;
 	return st.pos;
 }
@@ -7065,14 +7069,14 @@ int mapreg_setregstr(int num,const char *str)
 	char *p;
 
 	if( (p=numdb_search(mapregstr_db,num))!=NULL )
-		free(p);
+		aFree(p);
 
 	if( str==NULL || *str==0 ){
 		numdb_erase(mapregstr_db,num);
 		mapreg_dirty=1;
 		return 0;
 	}
-	p=(char *)aCalloc(strlen(str)+1, sizeof(char));
+	p=(char *)aCallocA(strlen(str)+1, sizeof(char));
 	strcpy(p,str);
 	numdb_insert(mapregstr_db,num,p);
 	mapreg_dirty=1;
@@ -7102,7 +7106,7 @@ static int script_load_mapreg()
 				printf("%s: %s broken data !\n",mapreg_txt,buf1);
 				continue;
 			}
-			p=(char *)aCalloc(strlen(buf2) + 1,sizeof(char));
+			p=(char *)aCallocA(strlen(buf2) + 1,sizeof(char));
 			strcpy(p,buf2);
 			s=add_str(buf1);
 			numdb_insert(mapregstr_db,(i<<24)|s,p);
@@ -7170,7 +7174,7 @@ static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
 }
 
 /*==========================================
- * 
+ *
  *------------------------------------------
  */
 static int set_posword(char *p)
@@ -7256,7 +7260,7 @@ static int mapreg_db_final(void *key,void *data,va_list ap)
 }
 static int mapregstr_db_final(void *key,void *data,va_list ap)
 {
-	free(data);
+	aFree(data);
 	return 0;
 }
 static int scriptlabel_db_final(void *key,void *data,va_list ap)
@@ -7265,8 +7269,8 @@ static int scriptlabel_db_final(void *key,void *data,va_list ap)
 }
 static int userfunc_db_final(void *key,void *data,va_list ap)
 {
-	free(key);
-	free(data);
+	aFree(key);
+	aFree(data);
 	return 0;
 }
 int do_final_script()
@@ -7274,7 +7278,7 @@ int do_final_script()
 	if(mapreg_dirty>=0)
 		script_save_mapreg();
 	if(script_buf)
-		free(script_buf);
+		aFree(script_buf);
 
 	if(mapreg_db)
 		numdb_final(mapreg_db,mapreg_db_final);
@@ -7286,9 +7290,9 @@ int do_final_script()
 		strdb_final(userfunc_db,userfunc_db_final);
 
         if (str_data)
-            free(str_data);
+            aFree(str_data);
         if (str_buf)
-            free(str_buf);
+            aFree(str_buf);
 
 	return 0;
 }

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 342 - 114
src/map/skill.c


+ 8 - 7
src/map/skill.h

@@ -186,7 +186,7 @@ enum {
 enum {	// struct map_session_data の status_changeの番?テ?ブル
 // SC_SENDMAX未?はクライアントへの通知あり。
 // 2-2次職の値はなんかめちゃくちゃっぽいので暫定。たぶん?更されます。
-	SC_SENDMAX			=128,
+	SC_SENDMAX			= 128,	// note: max is now 182, but we'll need to do alot of moving around
 	SC_PROVOKE			= 0,
 	SC_ENDURE			= 1,
 	SC_TWOHANDQUICKEN	= 2,
@@ -275,8 +275,10 @@ enum {	// struct map_session_data 
 
 	SC_STONE			= 128,
 	SC_FREEZE			= 129,
+// <-- 130 = a baby skill status?
 	SC_STAN				= 130,
 	SC_SLEEP			= 131,
+// <-- 132 = another baby skill?
 	SC_POISON			= 132,
 	SC_CURSE			= 133,
 	SC_SILENCE			= 134,
@@ -322,17 +324,15 @@ enum {	// struct map_session_data 
 	SC_DONTFORGETME		=175,
 	SC_FORTUNE			=176,
 	SC_SERVICE4U		=177,
-
 	SC_SPIDERWEB		=180,		/* スパイダ?ウェッブ */
-	SC_MEMORIZE			=181,		/* メモライズ */
-	SC_DPOISON			=182,		/* 猛毒 */
 //	SC_EDP							// moved
 	SC_SACRIFICE		=184,		/* サクリファイス */
 	SC_WEDDING			=187,	//結婚用(結婚衣裳になって?くのが?いとか)
 	SC_NOCHAT			=188,	//赤エモ?態
 	SC_SPLASHER			=189,	/* ベナムスプラッシャ? */
 	SC_SELFDESTRUCTION	=190,	/* 自爆 */
-
+	SC_MEMORIZE			=197,		/* メモライズ */ // changed from 181 to 192
+	SC_DPOISON			=198,		/* 猛毒 */
 
 // Used by English Team
 	SC_BROKNARMOR		=32,
@@ -348,6 +348,8 @@ enum {	// struct map_session_data 
 	SC_ENSEMBLE			=159,
 	SC_FOGWALL			=178,
 	SC_GOSPEL			=179,
+	SC_PRESERVE         =181,
+	SC_BATTLEORDERS		=182,
 	SC_MOONLIT			=183,
 	SC_ATKPOT			=185,	// [Valaris]
 	SC_MATKPOT			=186,	// [Valaris]
@@ -357,9 +359,8 @@ enum {	// struct map_session_data 
 	SC_BLOCKSKILL		=194, // for disallowing the use of a skill for a time period
 	SC_ADAPTATION		=195,
 	SC_CHASEWALK		=196,
-	SC_BATTLEORDERS		=200,
 	SC_REGENERATION		=201,
-	SC_PRESERVE         =202,
+	
 
 // [Celest]
 	SC_BLEEDING			= 124, // Temporarily same id as headcrush	

+ 6 - 6
src/map/storage.c

@@ -65,13 +65,13 @@ int do_init_storage(void) // map.c::do_init()
 static int guild_storage_db_final(void *key,void *data,va_list ap)
 {
 	struct guild_storage *gstor=data;
-	free(gstor);
+	aFree(gstor);
 	return 0;
 }
 static int storage_db_final(void *key,void *data,va_list ap)
 {
 	struct storage *stor=data;
-	free(stor);
+	aFree(stor);
 	return 0;
 }
 void do_final_storage(void) // by [MC Cameri]
@@ -87,7 +87,7 @@ struct storage *account2storage(int account_id)
 	struct storage *stor;
 	stor=numdb_search(storage_db,account_id);
 	if(stor == NULL) {
-		stor = aCalloc(sizeof(struct storage), 1);
+		stor = aCallocA(sizeof(struct storage), 1);
 		if(stor == NULL){
 			printf("storage: out of memory!\n");
 			exit(0);
@@ -109,7 +109,7 @@ int storage_delete(int account_id)
 	struct storage *stor = numdb_search(storage_db,account_id);
 	if(stor) {
 		numdb_erase(storage_db,account_id);
-		free(stor);
+		aFree(stor);
 	}
 	return 0;
 }
@@ -381,7 +381,7 @@ struct guild_storage *guild2storage(int guild_id)
 	if(guild_search(guild_id) != NULL) {
 		gs=numdb_search(guild_storage_db,guild_id);
 		if(gs == NULL) {
-			gs = aCalloc(sizeof(struct guild_storage), 1);
+			gs = aCallocA(sizeof(struct guild_storage), 1);
 			if(gs==NULL){
 				printf("storage: out of memory!\n");
 				exit(0);
@@ -398,7 +398,7 @@ int guild_storage_delete(int guild_id)
 	struct guild_storage *gstor = numdb_search(guild_storage_db,guild_id);
 	if(gstor) {
 		numdb_erase(guild_storage_db,guild_id);
-		free(gstor);
+		aFree(gstor);
 	}
 	return 0;
 }

+ 3 - 3
src/map/vending.c

@@ -48,7 +48,7 @@ void vending_vendinglistreq(struct map_session_data *sd,int id)
  */
 void vending_purchasereq(struct map_session_data *sd,int len,int id,unsigned char *p)
 {
-	int i, j, w, z, new = 0, blank, vend_list[12];
+	int i, j, w, z, new_ = 0, blank, vend_list[12];
 	short amount, index;
 	struct map_session_data *vsd = map_id2sd(id);
 
@@ -99,8 +99,8 @@ void vending_purchasereq(struct map_session_data *sd,int len,int id,unsigned cha
 		case ADDITEM_EXIST:
 			break;
 		case ADDITEM_NEW:
-			new++;
-			if (new > blank)
+			new_++;
+			if (new_ > blank)
 				return;	// Ží—Þ�”’´‰ß
 			break;
 		case ADDITEM_OVERAMOUNT:

+ 53 - 53
src/txt-converter/char/char-converter.c

@@ -16,16 +16,16 @@
 
 
 #define STORAGE_MEMINC	16
-	
+
 #include "char.h"
 #include "../../common/strlib.h"
 
 #ifdef MEMWATCH
 #include "memwatch.h"
 #endif
-	
+
 char pet_txt[256]="save/pet.txt";
-char storage_txt[256]="save/storage.txt";	
+char storage_txt[256]="save/storage.txt";
 
 MYSQL mysql_handle;
 MYSQL_RES* 	sql_res ;
@@ -89,18 +89,18 @@ int inter_pet_fromstr(char *str, struct s_pet *p)
 	int s;
 	int tmp_int[16];
 	char tmp_str[256];
-	
+
 	memset(p, 0, sizeof(struct s_pet));
-	
+
 //	printf("sscanf pet main info\n");
 	s=sscanf(str,"%d, %d,%[^\t]\t%d, %d, %d, %d, %d, %d, %d, %d, %d", &tmp_int[0], &tmp_int[1], tmp_str, &tmp_int[2],
 		&tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10]);
 
 	if(s!=12)
 		return 1;
-	
+
 	p->pet_id = tmp_int[0];
-	p->class = tmp_int[1];
+	p->class_ = tmp_int[1];
 	memcpy(p->name, tmp_str, 24);
 	p->account_id = tmp_int[2];
 	p->char_id = tmp_int[3];
@@ -126,11 +126,11 @@ int inter_pet_fromstr(char *str, struct s_pet *p)
 //---------------------------------------------------------
 int inter_pet_tosql(int pet_id, struct s_pet *p) {
 	//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`)
-	
+
 	char tmp_sql[65535];
 	MYSQL_RES* 	sql_res ;
 	MYSQL_ROW	sql_row ;
-	
+
 	jstrescapecpy (t_name, p->name);
 	if(p->hungry < 0)
 		p->hungry = 0;
@@ -148,19 +148,19 @@ int inter_pet_tosql(int pet_id, struct s_pet *p) {
 	sql_row = mysql_fetch_row(sql_res);	//row fetching
 	if (!sql_row) //no row -> insert
 		sprintf(tmp_sql,"INSERT INTO `pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) VALUES ('%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
-			p->pet_id, p->class, t_name, p->account_id, p->char_id, p->level, p->egg_id,
+			p->pet_id, p->class_, t_name, p->account_id, p->char_id, p->level, p->egg_id,
 			p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate);
 	else //row reside -> updating
 		sprintf(tmp_sql, "UPDATE `pet` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'",
-			p->class, t_name, p->account_id, p->char_id, p->level, p->egg_id,
+			p->class_, t_name, p->account_id, p->char_id, p->level, p->egg_id,
 			p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate, p->pet_id);
 	mysql_free_result(sql_res) ; //resource free
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 		printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	printf ("pet dump success! - %d:%s\n", pet_id, p->name);
-	
+
 	return 0;
 }
 
@@ -168,22 +168,22 @@ int storage_tosql(int account_id,struct storage *p){
 	// id -> DB dump
 	// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
 	int i,j;
-	
+
 	j=0;
-	
+
 	//printf ("starting storage dump to DB - id: %d\n", account_id);
-	
+
 	//delete old data.
 	sprintf(tmp_sql,"DELETE FROM `storage` WHERE `account_id`='%d'",account_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 			printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//printf ("all storage item was deleted ok\n");
-	
+
 	for(i=0;i<MAX_STORAGE;i++) {
 		//printf ("save storage num: %d (%d:%d)\n",i, p->storage[i].nameid , p->storage[i].amount);
-		
+
 		if( (p->storage[i].nameid) && (p->storage[i].amount) ){
 			sprintf(tmp_sql,"INSERT INTO `storage` (`account_id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`card0`,`card1`,`card2`,`card3`,`broken`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
 			  p->account_id, p->storage[i].nameid, p->storage[i].amount, p->storage[i].equip,
@@ -212,7 +212,7 @@ int storage_fromstr(char *str, struct storage *p)
 	if(set!=2)
 		return 0;
 	if(str[next]=='\n' || str[next]=='\r')
-		return 1;	
+		return 1;
 	next++;
 	for(i=0;str[next] && str[next]!='\t';i++){
 		if(sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
@@ -233,7 +233,7 @@ int storage_fromstr(char *str, struct storage *p)
 			p->storage[i].broken  = tmp_int[11];
 			next += len;
 			if (str[next] == ' ')
-				next++;	
+				next++;
 		}
 
 		else if(sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
@@ -251,12 +251,12 @@ int storage_fromstr(char *str, struct storage *p)
 			p->storage[i].card[1] = tmp_int[8];
 			p->storage[i].card[2] = tmp_int[9];
 			p->storage[i].card[3] = tmp_int[10];
-			p->storage[i].broken = 0;	
+			p->storage[i].broken = 0;
 			next += len;
 			if (str[next] == ' ')
-				next++;	
+				next++;
 		}
-		
+
 		else return 0;
 	}
 	return 1;
@@ -337,7 +337,7 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p) {
 	p->char_id = tmp_int[0];
 	p->account_id = tmp_int[1];
 	p->char_num = tmp_int[2];
-	p->class = tmp_int[3];
+	p->class_ = tmp_int[3];
 	p->base_level = tmp_int[4];
 	p->job_level = tmp_int[5];
 	p->base_exp = tmp_int[6];
@@ -508,10 +508,10 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p) {
 //==========================================================================================================
 int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 	int i,save_flag;
-	
+
 	save_flag = char_id;
 	printf("request save char data... (%d)\n",char_id);
-	
+
 	//`char`( `char_id`,`account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`, //9
 	//`str`,`agi`,`vit`,`int`,`dex`,`luk`, //15
 	//`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`, //21
@@ -525,7 +525,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 		"`option`='%d',`karma`='%d',`manner`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',"
 		"`hair`='%d',`hair_color`='%d',`clothes_color`='%d',`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d',"
 		"`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d', `partner_id` = '%d'",
-		char_id,p->account_id,p->char_num,p->name,p->class, p->base_level, p->job_level,
+		char_id,p->account_id,p->char_num,p->name,p->class_, p->base_level, p->job_level,
 		p->base_exp, p->job_exp, p->zeny,
 		p->max_hp, p->hp, p->max_sp, p->sp, p->status_point, p->skill_point,
 		p->str, p->agi, p->vit, p->int_, p->dex, p->luk,
@@ -535,17 +535,17 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 		p->last_point.map, p->last_point.x, p->last_point.y,
 		p->save_point.map, p->save_point.x, p->save_point.y, p->partner_id
 	);
-	
+
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 			printf("DB server Error (update `char`)- %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//`memo` (`memo_id`,`char_id`,`map`,`x`,`y`)
 	sprintf(tmp_sql,"DELETE FROM `memo` WHERE `char_id`='%d'",char_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 			printf("DB server Error (delete `memo`)- %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//insert here.
 	for(i=0;i<10;i++){
 		if(p->memo_point[i].map[0]){
@@ -560,7 +560,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 			printf("DB server Error (delete `inventory`)- %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//insert here.
 	for(i=0;i<MAX_INVENTORY;i++){
 		if(p->inventory[i].nameid){
@@ -579,7 +579,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 			printf("DB server Error (delete `cart_inventory`)- %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//insert here.
 	for(i=0;i<MAX_CART;i++){
 		if(p->cart[i].nameid){
@@ -593,14 +593,14 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 			}
 		}
 	}
-	
-	
+
+
 	//`skill` (`char_id`, `id`, `lv`)
 	sprintf(tmp_sql,"DELETE FROM `skill` WHERE `char_id`='%d'",char_id);
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 			printf("DB server Error (delete `skill`)- %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//insert here.
 	for(i=0;i<MAX_SKILL;i++){
 		if(p->skill[i].id){
@@ -618,7 +618,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 	if(mysql_query(&mysql_handle, tmp_sql) ) {
 			printf("DB server Error (delete `global_reg_value`)- %s\n", mysql_error(&mysql_handle) );
 	}
-	
+
 	//insert here.
 	for(i=0;i<p->global_reg_num;i++){
 		if(p->global_reg[i].value !=0){
@@ -629,10 +629,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
 			}
 		}
 	}
-	
+
 	printf("saving char is done... (%d)\n",char_id);
 	save_flag = 0;
-	
+
   return 0;
 }
 //==========================================================================================================
@@ -645,7 +645,7 @@ int mmo_char_init(void){
   char input;
   FILE *fp;
 
-	
+
 	//DB connection initialized
 	mysql_init(&mysql_handle);
 	printf("Connect DB server.... (inter server)\n");
@@ -658,7 +658,7 @@ int mmo_char_init(void){
 	else {
 		printf ("connect success! (inter server)\n");
 	}
-	
+
 
 
   printf("Warning : Make sure you backup your databases before continuing!\n");
@@ -667,14 +667,14 @@ int mmo_char_init(void){
   if(input == 'y' || input == 'Y'){
 	printf("\nConverting Character Database...\n");
 	fp=fopen("save/athena.txt","r");
-	char_dat=malloc(sizeof(char_dat[0])*256);
+	char_dat = (struct mmo_charstatus*)malloc(sizeof(char_dat[0])*256);
 	char_max=256;
 	if(fp==NULL)
 		return 0;
 	  while(fgets(line, 65535, fp)){
 	  if(char_num>=char_max){
 	      char_max+=256;
-	      char_dat=realloc(char_dat, sizeof(char_dat[0]) *char_max);
+	      char_dat = (struct mmo_charstatus*)realloc(char_dat, sizeof(char_dat[0]) *char_max);
 	    }
 	    memset(&char_dat[char_num], 0, sizeof(char_dat[0]));
 	    ret=mmo_char_fromstr(line, &char_dat[char_num]);
@@ -689,8 +689,8 @@ int mmo_char_init(void){
 	  printf("char data convert end\n");
 	  fclose(fp);
   }
-  
-  while(getchar() != '\n');  
+
+  while(getchar() != '\n');
   printf("\nDo you wish to convert your Storage Database to SQL? (y/n) : ");
   input=getchar();
   if(input == 'y' || input == 'Y') {
@@ -700,14 +700,14 @@ int mmo_char_init(void){
 		printf("cant't read : %s\n",storage_txt);
 		return 0;
 	}
-	
+
 	while(fgets(line,65535,fp)){
 		set=sscanf(line,"%d,%d",&tmp_int[0],&tmp_int[1]);
 		if(set==2) {
 			if(i==0){
-				storage=malloc(sizeof(struct storage));
+				storage = (struct storage*)malloc(sizeof(struct storage));
 			}else{
-				storage=realloc(storage,sizeof(struct storage)*(i+1));
+				storage = (struct storage*)realloc(storage,sizeof(struct storage)*(i+1));
 			}
 			memset(&storage[i],0,sizeof(struct storage));
 			storage[i].account_id=tmp_int[0];
@@ -718,7 +718,7 @@ int mmo_char_init(void){
 	}
 	fclose(fp);
   }
-	
+
   while(getchar() != '\n');
   printf("\nDo you wish to convert your Pet Database to SQL? (y/n) : ");
   input=getchar();
@@ -726,8 +726,8 @@ int mmo_char_init(void){
 	printf("\nConverting Pet Database...\n");
 	if( (fp=fopen(pet_txt,"r")) ==NULL )
 		return 1;
-	
-	p=malloc(sizeof(struct s_pet));
+
+	p = (struct s_pet*)malloc(sizeof(struct s_pet));
 	while(fgets(line, sizeof(line), fp)){
 		if(p==NULL){
 			printf("int_pet: out of memory!\n");
@@ -792,7 +792,7 @@ int inter_config_read(const char *cfgName) {
 		}
 	}
 	fclose(fp);
-	
+
 	printf("Reading interserver configuration: Done\n");
 
 	return 0;
@@ -825,7 +825,7 @@ int char_config_read(const char *cfgName) {
 		}
 		fclose(fp);
 		printf("Reading configuration: Done\n");
-	
+
 	return 0;
 }
 

+ 3 - 3
src/txt-converter/char/char.h

@@ -24,9 +24,9 @@ struct mmo_map_server{
   char map[MAX_MAP_PER_SERVER][16];
 };
 
-int mapif_sendall(unsigned char *buf,unsigned int len);
-int mapif_sendallwos(int fd,unsigned char *buf,unsigned int len);
-int mapif_send(int fd,unsigned char *buf,unsigned int len);
+int mapif_sendall(char *buf,unsigned int len);
+int mapif_sendallwos(int fd,char *buf,unsigned int len);
+int mapif_send(int fd,char *buf,unsigned int len);
 
 extern int autosave_interval;
 

+ 5 - 5
src/txt-converter/common/mmo.h

@@ -87,7 +87,7 @@ struct s_pet {
 	int account_id;
 	int char_id;
 	int pet_id;
-	short class;
+	short class_;
 	short level;
 	short egg_id;//pet egg id
 	short equip;//pet equip name_id
@@ -105,7 +105,7 @@ struct mmo_charstatus {
 
 	int base_exp,job_exp,zeny;
 
-	short class;
+	short class_;
 	short status_point,skill_point;
 	int hp,max_hp,sp,max_sp;
 	short option,karma,manner;
@@ -168,7 +168,7 @@ struct party {
 
 struct guild_member {
 	int account_id, char_id;
-	short hair,hair_color,gender,class,lv;
+	short hair,hair_color,gender,class_,lv;
 	int exp,exp_payper;
 	short online,position;
 	int rsv1,rsv2;
@@ -237,8 +237,8 @@ struct guild_castle {
 	int Ghp4;
 	int Ghp5;
 	int Ghp6;
-	int Ghp7;	
-	int GID0;	
+	int Ghp7;
+	int GID0;
 	int GID1;
 	int GID2;
 	int GID3;

+ 4 - 4
src/txt-converter/login/login-converter.c

@@ -40,7 +40,7 @@ struct {
   int sex,delflag;
 } auth_fifo[AUTH_FIFO_SIZE];
 int auth_fifo_pos=0;
-struct {
+struct auth_dat_ {
 	int account_id, sex;
 	char userid[24], pass[24], lastlogin[24];
 	int logincount;
@@ -72,7 +72,7 @@ char db_server_logindb[32] = "ragnarok";
 int isGM(int account_id)
 {
 	struct gm_account *p;
-	p = numdb_search(gm_account_db,account_id);
+	p = (struct gm_account*)numdb_search(gm_account_db,account_id);
 	if( p == NULL)
 		return 0;
 	return p->level;
@@ -95,7 +95,7 @@ int read_gm_account()
 		if(line[0] == '/' || line[1] == '/' || line[2] == '/')
 			continue;
 
-		p=malloc(sizeof(struct gm_account));
+		p = (struct gm_account*)malloc(sizeof(struct gm_account));
 		if(p==NULL){
 			printf("gm_account: out of memory!\n");
 			exit(0);
@@ -145,7 +145,7 @@ int mmo_auth_init(void)
 
 
 	fp=fopen("save/account.txt","r");
-	auth_dat=malloc(sizeof(auth_dat[0])*256);
+	auth_dat = (struct auth_dat_*)malloc(sizeof(auth_dat[0])*256);
 	auth_max=256;
 	if(fp==NULL)
 		return 0;

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác