Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
ssbilling2 for linux (ported)
Goto page Previous  1, 2
 
Post new topic   Reply to topic Printable version
 View previous topic  Continuum Patching and Thoughts on a B... Post :: Post Fixed Subbill No more high CPU stress,...  View next topic  
Author Message
fatrolls
Novice


Age:29
Gender:Gender:Male
Joined: Jul 25 2013
Posts: 35
Offline

PostPosted: Sun Apr 06, 2014 9:19 am    Post subject: Reply to topic Reply with quote

yes SpaceHiker your issue is pretty simple I also had the same problem..

The person who ported this into linux did a very poor job he had a mindset like this

This works on 32bit cpu I need to port it to 64bit cpu and Linux what should do I? Okay first let me replace all the int's with long's lol sa_tongue.gif

That's why when you connect nothing happens. Now we are at a problem not knowing what was really a long before and what was really a int before.

Going crazy changing all the long's back into int's is worse you might break something.

But changing some common mistakes there is only 6 to fix it.

Biggest mistakes are with the packet readers

Code: Show/Hide

long GetLong(BYTE * Message, const SHORT Offset)
{   // Get a long from a char *
   return *(long*)&(Message[Offset]);
}


should be

Code: Show/Hide

Uint32 GetLong(BYTE * Message, const SHORT Offset)
{   // Get a long from a char *
   return *(Uint32*)&(Message[Offset]);
}


Second one looks like this

Code: Show/Hide

Uint32 GetLong(char * Message, const SHORT Offset)
{   // Get a long from a char *
   return *(Uint32*)&(Message[Offset]);
}


it should only read 4 bytes from packet stream not 8 even though it's called GetLong it really means get unsigned int

Now all those possible error messages will now also use this GetLong so the linkedlist will have errors now because it doesn't support unsigned int

So the final 3 errors will involve adding code to linkedlist (although it never probably uses the long version in linkedlist and you could just rename it to Uint32/DWORD still safer to just create a new ones).

Under

Code: Show/Hide

   void operator=(const int);                  // l-string = r-int;


add
Code: Show/Hide

   void operator=(const unsigned int);                  // l-string = r-uint;


Under

Code: Show/Hide

   void operator+=(const int);                  // l-string += r-int;


add

Code: Show/Hide

   void operator+=(const unsigned int);                  // l-string += r-uint;


Under

Code: Show/Hide

   _string operator+(const int);               // l-string + r-int;


add

Code: Show/Hide

   _string operator+(const unsigned int);               // l-string + r-uint;


Now comes filling in the codes just copy/paste the int version right under it and change to unsigned int

Like so

Code: Show/Hide

void _string::operator=(const unsigned int Number)
{
   char Message[50];
   itoa(Number, Message, 10);

   delete Text;

   Text = new char[ (Length = strlen(Message)) + 1 ];
   memcpy(Text, Message, Length + 1);
}


Code: Show/Hide

void _string::operator+=(const unsigned int Number)
{
   char Message[50];
   itoa(Number, Message, 10);

   char * new_pointer;

   new_pointer = new char[ (Length + strlen(Message)) + 1 ];
   memcpy(new_pointer, Text, Length);
   memcpy(&new_pointer[Length], Message, strlen(Message) + 1);

   delete Text;

   Text    =   new_pointer;
   Length   +=   strlen(Message);
}


Code: Show/Hide

_string _string::operator+(const unsigned int Number)
{
   char Message[50];
   itoa(Number, Message, 10);

   _string S;

   S.Text = new char[ (S.Length = Length + strlen(Message)) + 1 ];
   memcpy(S.Text, Text, Length);
   memcpy(&S.Text[Length], Message, strlen(Message) + 1);

   return S;
}


That's it now it should work.. I would change all the long's that should be uint32 or just int32 and it would probably make the biller take twice as less memory.

But hey it works good enough for me.. plus changing all those long's to uint32's will corrupt the saved user entries database not like it's compatible with SCOREMAN anymore.

Another fix to fix negative ports (this is only for GUI display it will work without this fix).

Replace all short Port with SHORT Port

since typedef unsigned short SHORT; it would make it unsigned too.

This is okay for now, But I recommend porting catid's ssbilling2 again to linux without making any of these find/replace mistakes would fix more issues which are unknown right now.

Another fix I just added to support more users which SSBilling2 considers illegal/invalid clients.

Code: Show/Hide

bool InvalidMachineID(long MachineID)
{
   /*if (MachineID == 101) return false;

   if (MachineID < 0) return true;

   if (MachineID < 2000) return true;
   */
   return false;
}
Back to top
View users profile Send private message Add User to Ignore List
fatrolls
Novice


Age:29
Gender:Gender:Male
Joined: Jul 25 2013
Posts: 35
Offline

PostPosted: Mon Apr 07, 2014 7:07 am    Post subject: Reply to topic Reply with quote

Converted the ASM in the ssbilling2-linux into C code, now Comms:EncryptMode=1 works without any problems.

Here is the code if anyone is interested.

Code: Show/Hide

#ifndef ENCRYPTION_H
#define ENCRYPTION_H
#endif


// Packet encryption

void Host::InitializeEncryption(unsigned int Key)
{
   if (SentKey == Key)
   {
      SSEncrTable.SSKey = 0;
      return;
   }

   SSEncrTable.SSKey = Key;

   // Do the ASM thing (Assembly rips provided by Coconut Emulator)
   // Initialize calculations
   
   //It's a regular pseudo-random number with +123 extra -fatrolls
   int SKey = (int)Key;
   int counter = 0;
   int remaining = 260; //sizeof(SSBuf)  = 520 / 2 = 260.
   do
   {
      SKey = 16807 * (SKey % 127773) - 2836 * (SKey / 127773) + 123;
      if ( SKey <= 0 )
         SKey += 2147483647;
      SSEncrTable.SSBuf[counter] = (SKey & 0xFF);
      SSEncrTable.SSBuf[counter+1] = (SKey >> 8) & 0xFF;
      counter += 2;
      --remaining;
   }
   while (remaining);
}

void Host::Encrypt(char * Message, unsigned short Length)
{
   if (SSEncrTable.SSKey == 0) return;

   unsigned int IV = SSEncrTable.SSKey;
   char buffer[520];
   memset(buffer, 0, 520);

   if (Message[0] == 0)
      memcpy(buffer, &Message[2], Length - 2);
   else
      memcpy(buffer, &Message[1], Length - 1);

   for (unsigned short Counter = 0; Counter < 520; Counter += 4)
   {
      IV = GetLong(buffer, Counter) ^ GetLong(SSEncrTable.SSBuf, Counter) ^ IV;

      *(unsigned int*)&buffer[Counter] = IV;
   }

   if (Message[0] == 0)
      memcpy(&Message[2], buffer, Length - 2);
   else
      memcpy(&Message[1], buffer, Length - 1);
}

void Host::Decrypt(char * Message, unsigned short Length)
{
   if (SSEncrTable.SSKey == 0) return;

   unsigned int IV = SSEncrTable.SSKey;
   unsigned int ESI;
   unsigned int EDX;
   char buffer[520];
   memset(buffer, 0, 520);

   if (Message[0] == 0)
      memcpy(buffer, &Message[2], Length - 2);
   else
      memcpy(buffer, &Message[1], Length - 1);

   for (unsigned short Counter = 0; Counter < 520; Counter += 4)
   {
      EDX = GetLong(buffer, Counter);
      ESI = GetLong(SSEncrTable.SSBuf, Counter) ^ IV ^ EDX;
      IV = EDX;
      *(unsigned int*)&buffer[Counter] = ESI;
   }

   if (Message[0] == 0)
      memcpy(&Message[2], buffer, Length - 2);
   else
      memcpy(&Message[1], buffer, Length - 1);
}


// One-way encryption algorithms

void HashPassword(char * Password)
{
   size_t StrLen = strlen((char*)Password);
   unsigned short Factor = 0;
   char Char;
   size_t L = 0;
   for (L = 0; L < StrLen; L++)
      Factor ^= Password[L];

   for (L = 0; L < StrLen; L++)
   {
      Char = (Password[L] ^= Factor);
      Factor = (Factor ^ (Char << (Char & 3))) & 255;
      if (Password[L] == 0)
         Password[L] = 0xED;
   }
}

unsigned long HashModemInfo(char * Info)
{
    unsigned long h = 0, g;

   for (short i = 0; i < 608; i++)
    {
        h = ( h << 4 ) + *Info++;
        if ( g = h & 0xF0000000 )
            h ^= g >> 24;
        h &= ~g;
    }

    return h;
}
Back to top
View users profile Send private message Add User to Ignore List
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Mon Apr 07, 2014 2:16 pm    Post subject: Reply to topic Reply with quote

Nice to see someone has taken an interest in this icon_smile.gif Sorry for all the bugs I don't think i was worried too much abut 64-bit in 2007 biggrin.gif
_________________
Rediscover online gaming. Get Subspace | STF The future...prehaps
Back to top
View users profile Send private message Add User to Ignore List
fatrolls
Novice


Age:29
Gender:Gender:Male
Joined: Jul 25 2013
Posts: 35
Offline

PostPosted: Mon Apr 07, 2014 6:29 pm    Post subject: Reply to topic Reply with quote

Here is my port I pretty much copied pasted stuff from your port but I used a clean catid ssbilling2 from http://mervbot.com/files/ssb2confess.rar made by confess+. Although my version can't compile on windows like yours can, it's probably not to hard to fix up to work for windows. It saves users and EncryptMode=1 works. Haven't had it crash for 2 days now but I compile it with -g flag so if it crashes I could see the line number where it crashed.


Compiles with no warnings or errors on my CentOS 6 Linux but I use a old version of g++ because new versions are too strict.

Here is the compile log

Code: Show/Hide

[root@test biller]# make all
[root@test biller]# g++ -c main.cpp -o main.o   -D_REENTRANT -m64 -g
[root@test biller]# g++ main.o  -o "ssbilling2-linux" -lpthread -m64 -g
[root@test biller]#


I attached it it's also beautified (no tabs) / 4 spaces / always close with bracket.




FatRolls port of Confress+ SSBilling2 and Doc Flappy's linux fixes.

ssbilling linux.zip - 224 KB
File downloaded or viewed 11 time(s)
Back to top
View users profile Send private message Add User to Ignore List
SpaceHiker
Newbie


Joined: Apr 05 2014
Posts: 3
Offline

PostPosted: Sun Apr 13, 2014 5:37 pm    Post subject: Reply to topic Reply with quote

This is awesome, thanks!
Back to top
View users profile Send private message Add User to Ignore List
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2579
Location: USA
Offline

PostPosted: Sun Apr 13, 2014 7:15 pm    Post subject: Reply to topic Reply with quote

For those interested, I've posted ssbilling from Confess (2.0c) to bitbucket.

https://bitbucket.org/cypherjf/ssbilling-server/overview

I'm planning to add in my future tweaks to it - but it may be helpful to start merging some of this together?
_________________
Performance is often the art of cheating carefully. - James Gosling
Back to top
View users profile Send private message Add User to Ignore List
SpaceHiker
Newbie


Joined: Apr 05 2014
Posts: 3
Offline

PostPosted: Thu Apr 17, 2014 11:36 pm    Post subject: Reply to topic Reply with quote

fatrolls, can you tell me your gcc --version and your g++ --version?

Thanks
Back to top
View users profile Send private message Add User to Ignore List
Cheese
Wow Cheese is so helpful!


Joined: Mar 18 2007
Posts: 1011
Offline

PostPosted: Fri Apr 18, 2014 3:25 am    Post subject: Reply to topic Reply with quote

ive been making a modular client in the exact same style as asss, and i intend to make a biller and directory as well, and all 4 will be available on bitbucket for anyone to update

if you can write a module for one you can make a module for any

gonna call them SSCS SSCC SSCD SSCB

still deciding whether im going to put them all in the same bitbucket or 4 separate ones
each will have a major.minor.version versioning system
gonna keep directory and biller at major version 0 until they first successfully connect to a subgame zone/client


my intent is to make a centralized thing that will be the standardized thing that everyone uses, and ideally id like to have it be completely open sourced to where people cant recompile cheating versions because the public open source security module is good enough to keep things clean
i dont like this "security through obscurity" bullshit
i want it to be unbreakable, and i want people to know why its unbreakable
ive also had some ideas about periodically changing memory values and shuffling around pointers to prevent/detect memory hacks


i have been planning to have all the cores written from may-july, which sucks because the ddos made ssc zone owners switch many months earlier than i had the biller written


something else ive been deciding on is if i want biller to save to dat files or a mysql database, but i suppose i could write 2 modules that are interchangeable
also going to carry over groupdef to biller, so same concepts will apply instead of the level0-4 thing


once i finally get the time to get this shit done the game will be forever liberated from priits stranglehold on the game, effectively enabling the game to pretty much be immortal
downside is that its a shit ton of work and once i make it all open source theres a very good chance that literally noone else will bother working on it because i was 10 years late to the party



also cypher can you keep that bitbucket up for at least half a year?
also it would probably be good if you remove the dsp/dsw/vcproj/sln compiler specific cruft






the above is a collection of thoughts saved for later
_________________
SSC Distension Owner
SSCU Trench Wars Developer
Back to top
View users profile Send private message Add User to Ignore List Visit posters website AIM Address
fatrolls
Novice


Age:29
Gender:Gender:Male
Joined: Jul 25 2013
Posts: 35
Offline

PostPosted: Fri Apr 18, 2014 9:01 pm    Post subject: Reply to topic Reply with quote

SpaceHiker wrote:
fatrolls, can you tell me your gcc --version and your g++ --version?

Thanks


Sure

Code: Show/Hide

[root@test~]# g++ --version
(GCC) 3.4.6 20060404 (Red Hat 3.4.6-19.el6)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


You can downgrade using yum downgrade or yum install compact-gcc-34 something like that
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Misc User Apps All times are GMT - 5 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 90 page(s) served in previous 5 minutes.

phpBB Created this page in 0.076929 seconds : 36 queries executed (38.5%): GZIP compression disabled