Server Help

ASSS Custom Projects - <C> ASSS RPG Module

Cheese - Sun Sep 27, 2009 1:57 am
Post subject: <C> ASSS RPG Module
The RPG Module is simple:
It allows any zone to have permanent ships, saved across logouts and zone crashes.
The ships are saved in 2 tables in a mySQL database.
This module only remembers ships and players, you must write a module to make changes to the ships, using the interface.
Module produces no output. (besides log)
No powers are available.
Source attached.

For Global.conf:
Code: Show/Hide

[RPG]
Autosave=600 //in seconds


For Arena.conf
Code: Show/Hide

[Kill]
EnterDelay=500 //in centiseconds, uses this value
//be sure to have this in arena.conf, not arena.cfg


To create database tables:
Code: Show/Hide

CREATE TABLE `rpgplayer` (
  `UserId` int(10) unsigned NOT NULL auto_increment,
  `UserName` varchar(20) NOT NULL,
  `ShipID0` int(10) NOT NULL default '-1',
  `ShipID1` int(10) NOT NULL default '-1',
  `ShipID2` int(10) NOT NULL default '-1',
  `ShipID3` int(10) NOT NULL default '-1',
  `ShipID4` int(10) NOT NULL default '-1',
  `ShipID5` int(10) NOT NULL default '-1',
  `ShipID6` int(10) NOT NULL default '-1',
  `ShipID7` int(10) NOT NULL default '-1',
  PRIMARY KEY  (`UserId`),
  UNIQUE KEY `UserName` (`UserName`),
  UNIQUE KEY `UserName_2` (`UserName`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `rpgship` (
  `Ship` int(10) unsigned NOT NULL,
  `ShipId` int(10) unsigned NOT NULL auto_increment,
  `UserId` int(10) unsigned NOT NULL,
  `ROT` int(10) unsigned NOT NULL default '0',
  `THR` int(10) unsigned NOT NULL default '0',
  `SPD` int(10) unsigned NOT NULL default '0',
  `NRG` int(10) unsigned NOT NULL default '0',
  `RECH` int(10) unsigned NOT NULL default '0',
  `Gun` int(10) unsigned NOT NULL default '0',
  `Bomb` int(10) unsigned NOT NULL default '0',
  `Shrap` int(10) unsigned NOT NULL default '0',
  `Prox` int(10) unsigned NOT NULL default '0',
  `Multi` int(10) unsigned NOT NULL default '0',
  `Bounce` int(10) unsigned NOT NULL default '0',
  `Stealth` int(10) unsigned NOT NULL default '0',
  `Cloak` int(10) unsigned NOT NULL default '0',
  `Xradar` int(10) unsigned NOT NULL default '0',
  `Anti` int(10) unsigned NOT NULL default '0',
  `Rep` int(10) unsigned NOT NULL default '0',
  `Burst` int(10) unsigned NOT NULL default '0',
  `Decoy` int(10) unsigned NOT NULL default '0',
  `Thor` int(10) unsigned NOT NULL default '0',
  `Brick` int(10) unsigned NOT NULL default '0',
  `Rocket` int(10) unsigned NOT NULL default '0',
  `Portal` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`ShipId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1


Known limitations:
Database tables must be originally created before module use, else crash.
Only 1 arena can be attached at a time, as data is saved under 1 name. (might change later)
Avoid loading in game, any entered players can cause instability.
Database crashes should cause the module to suicide, not crash.
Quick changing produces no prizing, instead of crash.

to-do list:
table auto-create
multiple tables/arenas
replace suicide with db check+iface
Anonymous - Sun Sep 27, 2009 2:06 am
Post subject:
made sample module that makes use of the interface.

this is a sneeze away from working properly.
however, i am terrible with pointers and memory allocation.

currently crashes, need someone to take a look at why...
crash is reached just before check 3.



-edit-
anonymous posting is now a pain in the ass
Anonymous - Sun Sep 27, 2009 2:08 am
Post subject:
and i see that mgb still has yet to fix my signature...
Cheese - Mon Sep 28, 2009 12:22 am
Post subject:
i have no debugger, so i have to add log messages and recompile...

its wierd, its looking like function is called, but the zone crashes before it ever actually gets to the content, does anyone know why that might happen?
Dr Brain - Mon Sep 28, 2009 6:28 am
Post subject:
Get a debugger. Hobbyist or professional, you need to learn how to use one.
Doc Flabby - Mon Sep 28, 2009 7:32 am
Post subject:
Is there an easy way to debug ASSS i've stuggled on windows to find a good way of doing it (short of recompiling the whole thing in visual studio, which itself has a number of problems.) Whats the recommended way of debugging a ASSS module.
Dr Brain - Mon Sep 28, 2009 10:33 am
Post subject:
I just tried the mingw gdb on my windows laptop. I didn't put it through its paces, but it did start and run asss (compiled with mingw).
Cheese - Mon Sep 28, 2009 4:39 pm
Post subject:
gdb backtrace:

Code: Show/Hide

Program received signal SIGSEGV, Segmentation fault.
[Switching to thread 1092.0x1748]
0x6b901213 in FreqChange (p=0x199be20, newfreq=12) at rpg2.c:28
28                      ship=rpg->GetPlayerShip(p,shipnum);
(gdb) bt
#0  0x6b901213 in FreqChange (p=0x199be20, newfreq=12) at rpg2.c:28
#1  0x0041e1df in ?? ()
#2  0x0041e3af in ?? ()
#3  0x0040eb91 in ?? ()
#4  0x0040e974 in ?? ()
#5  0x6118132a in ptw32_threadStart@4 ()
#6  0x77c3a3b0 in _libmsvcrt_a_iname ()
#7  0x7c80b713 in _libmsvcrt_a_iname ()



^after you attempt freq change
JoWie - Mon Sep 28, 2009 4:41 pm
Post subject:
recompile your module with debugging symbols ( -g3 ) and post backtrace again
JoWie - Mon Sep 28, 2009 4:48 pm
Post subject:
Also, I have done debugging with gdb on windows and it works. But 10% of the crashes end up with a corrupt stack. Which is VERY annoying.

I tried to compile my modules in Visual Studio, but last i checked it does not support C99, so that requires to rewrite a LOT of stuff (variable declarations not at the start of functions)

Best way is to run linux in a virtual machine like VirtualBox (supports port forwarding)
Dr Brain - Mon Sep 28, 2009 6:10 pm
Post subject:
You're missing checks to make sure you got the modules from mm->GetInterface. You never register your interface. If you had the checks (like every other asss module), you'd have notice almost immediately.

See how much easier it is with a debugger? icon_smile.gif
Hakaku - Mon Sep 28, 2009 6:20 pm
Post subject:
One thing I noticed which you still have yet to fix in your color module, is this:
Code: Show/Hide
   else if (action == MM_UNLOAD)
   {
      mm->ReleaseInterface(chat);
      mm->ReleaseInterface(game);
      mm->ReleaseInterface(lm);
      mm->ReleaseInterface(pd);
      mm->ReleaseInterface(rpg);

      lm->Log(L_ERROR,"<rpg> Module has been unloaded.");

      return MM_OK;
   }

You shouldn't be using the log interface after you just finished releasing it.

Also, why are you committing suicide / unloading the entire module if you can't connect to the database a single time? The problem with this is that if another module is using your interface, it won't unload properly and may cause instability in the module using it, potentially causing the zone to crash. (that or you'll have to forcebly ?shutdown -r to have them removed)
Cheese - Mon Sep 28, 2009 6:44 pm
Post subject:
i do have the interface checks, i never use/need them, but since this was being a huge pain in the ass, i did.
additionally, i already knew the error line:
ship=rpg->GetPlayerShip(p,shipnum);
meaning an interface error, still requiring no use of a debugger.

the interface is never registered, despite attempts to register it to one or all arenas...
Cheese!> and since reginterface doesnt return anything, i dont know if its being created


@hakaku
thanks for noticing, i originally had it at the beginning of the unload process, but decided to report the module as unloaded after it actually unloaded.
im guessing that error is now in everything i have made to date.
i suppose from now on itll just signal the beginning of the unload process...

also, having this registering works:
Code: Show/Hide

mm->RegInterface(&iface,ALLARENAS);
      local Irpg *rpg;
      rpg=mm->GetInterface(I_RPG,ALLARENAS);
      if (!rpg)
      {
           lm->Log(L_ERROR,"interface not registered");
      }
      else
      {
           lm->Log(L_ERROR,"interface is good");//always this
      }
      mm->ReleaseInterface(rpg);


yet while loading the second module to get the interface always fails:
Code: Show/Hide


      local Irpg *rpg;
...
rpg=mm->GetInterface(I_RPG,ALLARENAS);
      if (!rpg)
      {
           lm->Log(L_ERROR,"no interface");//always this
      }
      else
      {
           lm->Log(L_ERROR,"interface good");
      }

Dr Brain - Mon Sep 28, 2009 6:52 pm
Post subject:
Your code says you don't have interface checks.

It's not an interface error. Your pointer to rpg is NULL, because you never acquired the interface. If you had checks, you'd have noticed.

You don't call RegInterface. I don't see any attempts to register it to one or all arenas.
Cheese - Mon Sep 28, 2009 7:04 pm
Post subject:
heres updated files (similarly nonworking), with more debug messages.
rpg2 was compiled with -g3

Cheese!> ill worry about stability after it works
Cheese!> no need for brakes on a nonmoving car, imo

heres where you say 'no need for a parachute until you realize youre falling', amirite?
Dr Brain - Mon Sep 28, 2009 7:30 pm
Post subject:
Your code actually looks like this:

Code: Show/Hide
   if (action == MM_LOAD)
   {
      lm=mm->GetInterface(I_LOGMAN,ALLARENAS);
      game=mm->GetInterface(I_GAME,ALLARENAS);
      chat=mm->GetInterface(I_CHAT,ALLARENAS);
      pd=mm->GetInterface(I_PLAYERDATA,ALLARENAS);
      local Irpg *rpg2;
      rpg2=mm->GetInterface(I_RPG,ALLARENAS);
      if (!rpg)
      {
           lm->Log(L_ERROR,"no interface");
      }
      else
      {
           lm->Log(L_ERROR,"interface good");
      }
      mm->ReleaseInterface(rpg2);
      
      lm->Log(L_ERROR,"<rpg2> Module has been loaded.");
       
      return MM_OK;




Unlike the snippet you posted, the actual code does not initialize rpg. It only sets rpg2.

Still think checks are stupid?
Cheese - Mon Sep 28, 2009 8:05 pm
Post subject:
id personally like to thank you all for your help, everything works nicely now.

it seems my code was fine, the interface just wasnt being initialized properly.

the files have been updated.
i think ill make it possible to have multiple arenas with multiple db tables later...
Bak - Mon Sep 28, 2009 9:44 pm
Post subject:
why not use persist?
JoWie - Tue Sep 29, 2009 5:03 am
Post subject:
I told you all of this yesterday...
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group