Vagrancy™ Posted August 22, 2013 Posted August 22, 2013 hello guys i decided to share a cool code for online statistics and Announcements! Its something simple. online statistics Adding to DB: CREATE PROCEDURE [dbo].[playersnumber] --@pl_number int output AS --SELECT @pl_number=count(*) FROM user_data WHERE login>logout AND logout>0 AND login>0 SELECT count(*) FROM user_data with (nolock) WHERE login>logout GO And here is the Script...(Php) PHP Code: <?php $flogin = fsockopen ("000.000.000.000",2106, $errno, $errstr, 1);//Instead 000.000.000.000 Ip Server if ( $flogin ) $login_s = "Online"; else $login_s = "Offline"; $fgame = fsockopen ("000.000.000.000",7777, $errno, $errstr, 1); if ( $flogin ) $game_s = "Online"; else $game_s = "Offline"; $mssql_server="000.000.000.000"; //Instead 000.000.000.000 Ip Server $mssql_db="lin2world"; $CONN = mssql_connect($mssql_server, 'user', 'pass'); if ($CONN) { mssql_select_db($mssql_db); $result = mssql_query("exec playersnumber", $CONN); $online=mssql_fetch_row($result); $online=$online[0]; } else $on_line = 0; //image size $im = imagecreate(X, Y); $im = imagecreate(100, 45); $str = "Online: "; // $bg - the background color, $textcolor - text color $bg = imagecolorallocate($im, 213, 248, 225); $textcolor = imagecolorallocate($im, 0, 0, 0); // Output lines in the picture //imagestring($im, The font size for the X coordinate, coordinate, Y, "Login: ", $textcolor); imagestring($im, 3, 0, 0, "Login: ", $textcolor); imagestring($im, 3, 53, 0, $login_s, $textcolor); imagestring($im, 3, 0, 15, "Game: ", $textcolor); imagestring($im, 3, 53, 15, $game_s, $textcolor); imagestring($im, 3, 0, 30, $str, $textcolor); imagestring($im, 3, 53, 30, $online, $textcolor); // output the image header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?> Online Announcement PHP Code: <?php DEFINE("SELECT_ONLINE","select count(*) from user_data where account_id>0 and online=1"); function connectdb($db, $dbaddress, $dbuser, $dbpass){ $dbconnect = mssql_connect ($dbaddress, $dbuser, $dbpass); mssql_select_db ($db, $dbconnect); } connectdb('lin2world', '172.16.192.34', 'sawa', 'dfsdfFdvh'); $result = mssql_query(sprintf(SELECT_ONLINE)); $accounts = mssql_fetch_array($result); $accounts = trim($accounts[0]); send_announce("Now online: ".$accounts." users"); exit; function send_announce($announce){ $buf=pack("c",70).tounicode($announce); $cachedsocket=@fsockopen("172.16.192.3","2012",$errno,$errstr,1) or die($notconnected); fwrite($cachedsocket,pack("s",(strlen($buf)+2)).$buf); $len=unpack("v",fread($cachedsocket,2)); $rid=unpack("c",fread($cachedsocket,1)); for($i=0;$i<(($len[1]-4)/4);$i++){ $read=unpack("i",fread($cachedsocket,4)); $rs.=$read[1]; } fclose($cachedsocket); } function tounicode($string){ $rs=""; for($i=0;$i<strlen($string);$i++) $rs.=$string[$i].chr(0); return($rs.chr(0).chr(0)); } ?> Thats all!If i made mistakes let me know! More shares soon
Tomoya Posted August 22, 2013 Posted August 22, 2013 I don't think it's a good way to define an "online" player: SELECT count(*) FROM user_data with (nolock) WHERE login>logout Same here: DEFINE("SELECT_ONLINE","select count(*) from user_data where account_id>0 and online=1"); I mean... It works in 99% of the cases, but the results can be random, count crashed players etc. Regards, Tomoya of L2Sublimity
Vagrancy™ Posted August 22, 2013 Author Posted August 22, 2013 Its tested for me and work fine on GF and c4! On interlude there is a problem when i run it but i will fix it soon!
Sighed Posted August 23, 2013 Posted August 23, 2013 Why don't use the hAuthD system ? it works fine, and doesn't need to connect to MSSQL.
Vagrancy™ Posted August 23, 2013 Author Posted August 23, 2013 Its old script(Tip) and maybe someone need that if the extender its old
Sighed Posted August 23, 2013 Posted August 23, 2013 The hAuthD script works with any hAuthD version, and for what i know any server works with hAuthD.
Vagrancy™ Posted August 23, 2013 Author Posted August 23, 2013 now yes all hAuthD version works maybe its useful for someone
mcbigmac Posted August 23, 2013 Posted August 23, 2013 The hAuthD script works with any hAuthD version, and for what i know any server works with hAuthD. hAuthd doesn't support Auto Registration - like GF AuthDaemon \ AuthGate does. So there's that niche possibilty.
Sighed Posted August 24, 2013 Posted August 24, 2013 hAuthd doesn't support Auto Registration - like GF AuthDaemon \ AuthGate does. So there's that niche possibilty. GF doesn't support it as well, it was some crap added by some of the previous owners of the files, not NcSoft, its just a stored procedure that has to me modified in order to disable that function. But we are talking about online status and players, what has to do that with ?
mcbigmac Posted August 24, 2013 Posted August 24, 2013 GF doesn't support it as well, it was some crap added by some of the previous owners of the files, not NcSoft, its just a stored procedure that has to me modified in order to disable that function. But we are talking about online status and players, what has to do that with ? hAuthd script only works with hAuthd. And you try use the modified GPwdWithFlag with hAuthd tell me what happens. Thus a similar script like this is needed - in those niches.
Sighed Posted August 24, 2013 Posted August 24, 2013 I know but we were talking about online and offline scripts, not about auto-registration :D I was talking about the hAuthD script for online and offline status, beacause its the Auth that most people use. The only thing that needs to be removed in that SP for deactivating the Auto-Registration feature is exec ap_AutoReg @account thats all, anyway extending other Auth like C4 there is a posibility of adding such feature.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now