Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Clan Files PHP Converted

RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
Hi All
Updoot:
Is now on gitlab repo:


If you feel you can improve it and wish to be a member, let me know and i'll add you as a repo member.
I'll add more scripts and tools in as I go. I have re-written Sanduurs Clan files into PHP
as well as Vormavs auto sod clan score script. (sod2.php)

Thought i'd share with the wider community.

Implementation:

Requirements:

PHP V5.3 or Higher
SQLSRV extension for PHP

Configure SQL connection information in
Code:
Clan/settings.php and ServerMain/Settings.php
as follows:
Code:
$server = "PTSERVER/SQLEXPRESS"; //Enter SQL Instance or IP with port (i.e. 192.168.0.1,1433)
$UID = 'USERID'; // Enter User ID For SQL Login
$PWD = 'PASSWORD'; // Enter SQL Password

Open client side executable, replace all the file links (search .asp) with .php extension.
Alternatively, rename the files to .asp and edit the handler mapping to use the php executable.
sod2 link is in sql.dll (or clan.dll, I forget), just follow Vormavs guide.

[STRIKE]If your Clandb CL table auto increments IDX you'll need to remove it from the query string in claninsert.php (instructions on which string are in the top of the file).

This is in there as if your table does not auto increment it will get Error(11) when creating clans without it. [/STRIKE]

All scripts are working, I have tested them thoroughly.

Bug: Clan Kick procedure, the character name in the get data doesnt translate correctly (found this with the ASP files too), I added a work around so for 99% of cases it works just fine, however, if the characters name contains Square brackets, it will not work and you'll need to manually kick the player.

When I work it out I'll release an update. (maybe its just my server/client combo)

Credits to Vormav and Sandurr for their files which I used as templates.
and to me for writing these ones (tagged as EuphoriA)

I hope people get some use from these :)

V2 Update:
I have added a query string to test if the IDX in clandb.dbo.cl and clandb.dbo.ul is autoincrementing.
This will adjust the query to suit.
V4 Update, fixed claninsert.php and re-added the check for auto increment on IDX and MIDX lines.

Version 5 (April 18) Update:
- Fixed clan kick procedure, can no do multi kick in one go.
- Fixed clan kick to handle names with square brackets ([])
- claninsert now creates the clan image when creating the clan based off the default template.


V6 Update:
- Converted to PDO - now requires PHP SQLSRV PDO module
- All settings in settings.ini, sets all parameters and cleans to prevent sql injection.
- cleaned up code a bit and sql strings.

note. isPFlag and isKFlag just return a code=1 because anything other than that won't let you talk to the clan master (errors)
 

Attachments

You must be registered for see attachments list
Last edited:
Initiate Mage
Joined
Jun 13, 2016
Messages
50
Reaction score
1
how to setup all clansystem php.
Can you show me about all guide. by pictures or by video .
Thank you show much.
 
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
I'll do a guide in the next few days, need to release another update (just to clean up error log, at present if it can't access the sql server it will still try execute the code which throws errors in the php error log).
 
Initiate Mage
Joined
Jun 13, 2016
Messages
50
Reaction score
1
thank so much. i will wait your guide.
I use clan system IIS work fine. but i want change to PHP for speed connection .
I can read code PHP . I will development with you.
 
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
the code all works, i just need to wrap the entire process in an
if ($dbconn) {}

I'll do a proper guide soon, but the long and the short of it is.

in game.exe file all instances of ".asp" and ".aspx" (will be claninsert.aspx, the rest will be .asp)

you'll find one for each of the files in my zip above

isClanMember, getAllMyClanMember, isPFlag, isKFlag,isClanWonSelfRelease, IsClanWon etc etc.

Replace the .asp with .php in each of those,

As for sod score its in sql.dll from memory (can check vormavs guide on the auto sod score).
 
Initiate Mage
Joined
Jun 13, 2016
Messages
50
Reaction score
1
i see. But i can't setup PHP run with clansystem . When i put
i had problem " can not load page " or Fatal error: Call to undefined function sqlsrv_connect() in C:\AppServ\www\Clan\claninsert.php on line 14
i know change link in game.exe .
i dont setup PHP for work with clan system.
Thank so much
 
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
you need the sqlsrv module for php,

 
Initiate Mage
Joined
Jun 13, 2016
Messages
50
Reaction score
1
not work . i use appserv for PHP language.
Can you show me about setup all PHP installer.
Thank so much
 
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
You need to download sqlsrv, what version of php are you running? 5.3? 7.0? thread safe? non thread safe?
you need the right sqlsrv for yours (i.e. if running 5.4 non thread safe then you need the php_sqlsrv_54_nts.dll and php_pdo_sqlsrv_54_nts.dll files), put them into the php/ext/ folder, then in php.ini (within the php folder) at the bottom add
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_sqlsrv_54_nts.dll
(change for the files that suit your version)

then restart www services (in services.msc, find World wide web services, right click -> restart)
then check it,

you can see if you have it enabled with:

create a file called info.php
<?php
echo phpinfo();
?>

browse to that page, (remove it from your website when you finish as its a security risk)
that will say which version of php, if its non thread safe or not, and you'll find a section to say if sqlsrv is operating
 
Last edited:
Initiate Mage
Joined
Jun 13, 2016
Messages
50
Reaction score
1
thank so much
can you use programs for installer PHP web server ?
I had try it. because i had use appserv 8.6.0 to installer web server.
 
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
I believe you can install php with the iis web application installer but to implement sqlsrv on it you need to do it manually, but the above steps are all you need.
 
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
updated version 3. has failsafe check to ensure connectivity to SQL DB before proceeding, (Prevents error log entries)
 
Experienced Elementalist
Joined
Oct 30, 2009
Messages
290
Reaction score
23
Version 3 clan files im using and i get this error.




Parse error: syntax error, unexpected '}' in C:\AppServ\www\clanfiles\ServerMain\isClanMember.php on line 19

Any suggestions on how to fix?

Update: fixed the syntax by just deleting the db connection detect you added in v3, no errors but when i make clans it takes my money and then doesnt make my clan into database, not sure what im doing wrong.
 
Last edited:
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
the db connection detect was to prevent it trying to run when it couldnt reach the db, i'll adjust and reupload when I get a chance,

relog and see if the char is in a clan after relog, I found error 11 came up when there wasnt an image file available. (clancontent folder)



Found my mistake, On line 18, add a semi colon (;) at the end of the line, so it looks like this

Code:
if (!$dbconn)
{
    die("Code=100$CR");
}



anyway, isClanMember is not part of adding a char to a clan, thats only on log on / in game to check if the member is in a clan,

Did you set the sql connection string correctly in Clan/claninsert.php ?? (Lines 6,7,8)



re-upped with V4,
Added some helpful error handling in claninsert.php
Made it write to the error log if its got issues.

New zip is smaller than previous so maybe i have an outdated servermain folder, will compare and re-up if different.

code for claninsert is now...

Code:
<?php   
 /**     
*         ClanInsert PHP Script    
*    Written By EuphoriA / Phatkone    
**/
$server = "PTSERVER/SQLEXPRESS"; 
//Enter SQL Instance or IP with port (i.e. 192.168.0.1,1433)
$UID = 'USERID';
 // Enter User ID For SQL Login
$PWD = 'PASSWORD'; 
// Enter SQL Password
/*** Main Script - Nothing needs to be edited past here.**/
$dbconn = sqlsrv_connect($server, array('UID' => "$UID", 'PWD' => "$PWD", 'CharacterSet' => 'UTF-8'));$CR = chr(13);    $errorlog = ini_get('php_errors');
$_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
if ($dbconn) 
{
        if (isset($_GET)) 
        {
                $userid = isset($_GET['userid'])? $_GET['userid']:"";
                $gserver = isset($_GET['gserver'])? $_GET['gserver']:""; 
                $chname = isset($_GET['chname'])? $_GET['chname']:"";
                $clname = isset($_GET['clName'])? $_GET['clName']:"";
                $chtype = isset($_GET['chtype'])? $_GET['chtype']:"";
                $lv = isset($_GET['lv'])? $_GET['lv']:"";
                $ticket = isset($_GET['ticket'])? $_GET['ticket']:"";
                $expl = "Pristontale Clan";
                if ($userid=="" || $gserver =="" || $chname=="" || $clname=="" || $chtype=="" || $lv=="" || $ticket=="")
                {
                       print("Code=102".$CR);  
                       error_log('Missing GET Value', $errorlog);
                       die; 
                }
                $ctcheck = "SELECT SNo FROM clandb.dbo.CT WHERE ChName='$chname' AND UserID='$userid'";
                $tticket = sqlsrv_query($dbconn, $ctcheck, array());
                $tticket1 = sqlsrv_fetch_array($tticket);
                if ($ticket != $tticket1[0])         
                {            
                          print("Code=101".$CR);
                          sqlsrv_close($dbconn);
                          error_log('Ticket does not match value in CT Database',$errorlog);
                          die;
                }
                $clancheck = "SELECT ClanName FROM clandb.dbo.UL WHERE ChName='$chname'";
                $clancheck1 = sqlsrv_query($dbconn, $clancheck);
                if ($clancheck1 != "") 
                {
                        $delete = "DELETE FROM clandb.dbo.UL WHERE ChName='$chname'";
                } else {
                        print("Code=2".$CR."CMoney=0".$CR);
                        sqlsrv_close($dbconn);
                        die;
                }
                $leader = "SELECT ClanZang FROM clandb.dbo.CL WHERE ClanName='$clname'";
                $leadercheck = sqlsrv_query($dbconn, $leader);
                $leadercheck1 = sqlsrv_fetch_array($leadercheck);
                if ($leadercheck1[0] != "") 
                {
                      sqlsrv_close($dbconn); 
                      print("Code=3".$CR."CMoney=0".$CR);
                      die;
                }
                $LI = "SELECT IMG FROM clandb.dbo.LI WHERE ID=1";
                $IMG = sqlsrv_query($dbconn,$LI, array());
                $IMG1 = sqlsrv_fetch_array($IMG);
                if ($IMG1[0] != "")
                {
                        $iIMG = $IMG1[0];
                 } else {
                        $iIMG = 1000000000;
                        $imginsert = "INSERT INTO clandb.dbo.LI ('$iIMG','1')";
                        sqlsrv_query($dbconn,$imginsert);
                 }
                 $iIMG = $iIMG + 1;
                 $imginsert = "UPDATE clandb.dbo.LI SET IMG='$iIMG' WHERE ID=1";
                 sqlsrv_query($dbconn, $imginsert);
                 $IDX = "SELECT MAX(IDX) FROM clandb.dbo.CL";
                 $IDX1 = sqlsrv_query($dbconn,$IDX, array());
                 $IDX2 = sqlsrv_fetch_array($IDX1);
                 $iIDX = 0;
                 if ($IDX2[0] != "")
                 {
                          $iIDX = $IDX2[0];
                 }
                 $iIDX = @$iIDX + 1;
                 $sdate = date("Y-m-d");
                 $edate = date('Y-m-d', strtotime('+20 years'));
        /* Check if IDX Value auto increments in CL table */   
                 $autoidxquery = "SELECT is_identity FROM sys.columns WHERE object_id = object_id('clandb.dbo.cl') AND name = 'IDX'";
                 $autoidxresult = sqlsrv_query($dbconn, $autoidxquery, array());
                 $autoidxresult = sqlsrv_fetch_array($autoidxresult);
                 if ($autoidxresult[0] == 1)
                 { 
                          $CLInsert = "INSERT INTO clandb.dbo.CL ([ClanName],[UserID],[ClanZang],[MemCnt],[Note],[MIconCnt],[RegiDate],[LimitDate],[DelActive],[PFlag],[KFlag],[Flag],[NoteCnt],[Cpoint],[CWin],[CFail],[ClanMoney],[CNFlag],[SiegeMoney]) values('$clname','$userid','$chname','1','$expl','$iIMG','$sdate','$edate','0','0','0','0','1','0','0','0','0','0','0')"; 
                 }
                 else 
                 {
                          $CLInsert = "INSERT INTO clandb.dbo.CL ([IDX],[ClanName],[UserID],[ClanZang],[MemCnt],[Note],[MIconCnt],[RegiDate],[LimitDate],[DelActive],[PFlag],[KFlag],[Flag],[NoteCnt],[Cpoint],[CWin],[CFail],[ClanMoney],[CNFlag],[SiegeMoney]) values('$iIDX','$clname','$userid','$chname','1','$expl','$iIMG','$sdate','$edate','0','0','0','0','1','0','0','0','0','0','0')";
                 }
                 sqlsrv_query($dbconn, $CLInsert);
                 $IDXCheck = "SELECT IDX FROM clandb.dbo.CL WHERE ClanName='$clname'";
                 $IDXC = sqlsrv_query($dbconn, $IDXCheck, array());
                 $IDXC1 = sqlsrv_fetch_array($IDXC);
                 if ($IDXC1[0] != "")
                 {
                           $IDX = $IDXC1[0]; 
                 }
                 $autoidxquery = "SELECT is_identity FROM sys.columns WHERE object_id = object_id('clandb.dbo.ul') AND name = 'IDX'";
                 $autoidxresult = sqlsrv_query($dbconn, $autoidxquery, array());
                 $autoidxresult = sqlsrv_fetch_array($autoidxresult);
                 if ($autoidxresult[0] == 1)
                 {
                           $ULInsert = "INSERT INTO clandb.dbo.UL ([MIDX],[userid],[ChName],[ClanName],[ChType],[ChLv],[Permi],[JoinDate],[DelActive],[PFlag],[KFlag],[MIconCnt]) values('3','$userid','$chname','$clname','$chtype','$lv','0','$sdate','0','0','0','$iIMG')";
                 }
                 else
                 {
                            $ULInsert = "INSERT INTO clandb.dbo.UL ([IDX],[MIDX],[userid],[ChName],[ClanName],[ChType],[ChLv],[Permi],[JoinDate],[DelActive],[PFlag],[KFlag],[MIconCnt]) values('$IDX','3','$userid','$chname','$clname','$chtype','$lv','0','$sdate','0','0','0','$iIMG')";
                 }
             sqlsrv_query($dbconn,$ULInsert);
             print("Code=1".$CR."CMoney=500000".$CR);
             sqlsrv_close($dbconn);
         }
         else
        {
               print "Missing GET Data";
        }
}
else 
{
        sqlsrv_close($dbconn);
        print("Code=103".$CR);
        print("Unable To Connect");\
        die;
}
?>
 
Last edited:
Experienced Elementalist
Joined
Oct 30, 2009
Messages
290
Reaction score
23
Okay so clans work, but when i go to invite somone it will not insert them into UL database, any clue why?
 
Initiate Mage
Joined
Aug 31, 2017
Messages
19
Reaction score
0
Hi guys, unable to connect to MSSQL 2008 R2 in VPS. Everything runs smoothly if I set up on local machine.

VPS OS is Windows Server 2012, not sure if that has anything to do with it.

Here is the error I am getting:

51.255.167.106:8080/clanfiles/Clan/clanInsert.php?userid=morrk&gserver=TestServer1&chname=Snow&clName=Westeros&expl=\xbc\xb3\xb8\xed\xbe\xf8\xc0\xbd.&ticket=467&chtype=4&lv=73

Any help would be greatly appreciated!
 
RZA-PT | KilroyPT
Joined
Aug 27, 2007
Messages
936
Reaction score
85
Update Version 5

- Auto creates the clan image when creating the clan (do not rename nor move the template file that is attached).
- fixed bug with deleting chars (wouldnt work if name had square brackets)
- have fixed the ability to kick multiple people at once.
 
Back
Top