Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Database connection info
- $db_hostname = "localhost"; //Hostname
- $db_port = 3306; //Port
- $db_username = ""; //Username
- $db_password = ""; //Password
- $db_database = ""; //Database
- //Steam info
- $steam_username = ""; //Steam username
- $steam_password = ""; //Steam password
- $steam_communityid = "";
- $steam_cookie = "";
- //Plugin info
- $plugin_groupid = ""; //Community ID of the group
- $plugin_invites = "250"; //Number of invites per day
- //Getting plugin info
- if(!file_exists("autoinvite.txt"))
- {
- touch("autoinvite.txt");
- $invites_sofar = 0;
- $time_of_last_max = 0;
- }
- else
- {
- list($invites_sofar, $steam_cookie, $time_of_first) = explode("\n", file_get_contents("autoinvite.txt"));
- }
- //Over the time limit, resetting
- if($time_of_first < (time()-7200))
- {
- $invites_sofar = 0;
- //Fetching Steam cookie
- $data = array("username" => $steam_username,
- "password" => $steam_password,
- "emailauth" => "",
- "captchagid" => "-1",
- "captcha_text" => "");
- $steam_login = curl_init();
- curl_setopt($steam_login, CURLOPT_URL, "https://steamcommunity.com/login/dologin/");
- curl_setopt($steam_login, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($steam_login, CURLOPT_HEADER, 1);
- curl_setopt($steam_login, CURLOPT_POST, 1);
- curl_setopt($steam_login, CURLOPT_POSTFIELDS, $data);
- $output=curl_exec($steam_login);
- if(preg_match("/steamLogin=(.*);/i", $output, $steam_cookie))
- $steam_cookie = $steam_cookie[1];
- curl_close($steam_login);
- }
- $steam_communityid = strstr($steam_cookie, "%", true);
- //Connect to database
- $mysqli_conn = new mysqli($db_hostname, $db_username, $db_password, $db_database, $db_port);
- $invites_now = 0;
- if($invites_sofar < $plugin_invites)
- {
- if(isset($_GET["communityid"]))
- {
- $result = invite_player($steam_communityid, $_GET["communityid"], $plugin_groupid, $steam_cookie);
- if(preg_match("/\<\!\[CDATA\[OK\]\]\>/", $result))
- {
- $invites_now++;
- $mysqli_conn->query("INSERT INTO invited_players (communityid) VALUES(\"".$mysqli_conn->real_escape_string($_GET["communityid"])."\")");
- }
- if($_GET["log"])
- {
- echo $result;
- }
- }
- if(($invites_sofar + $invites_now) < $plugin_invites)
- {
- //Fetch queued players and invite them
- $successful_invites = array();
- $mysql_query = $mysqli_conn->query("SELECT * FROM queued_players LIMIT 0, ".($plugin_invites-$invites_sofar-$invites_now));
- while($player = $mysql_query->fetch_assoc())
- {
- $result = invite_player($steam_communityid, $player["communityid"], $plugin_groupid, $steam_cookie);
- if(preg_match("/\<\!\[CDATA\[OK\]\]\>/", $result))
- {
- $invites_now++;
- $mysqli_conn->query("INSERT INTO invited_players (communityid) VALUES(\"".$player["communityid"]."\")");
- }
- $successful_invites[] = $player["communityid"];
- }
- //Delete successfully invited players from database
- $mysql_query_string = "DELETE FROM queued_players WHERE";
- for($i=0;$i<count($successful_invites);++$i)
- {
- $mysql_query_string .= " communityid=\"".$successful_invites[$i]."\"";
- if(($i+1) != count($successful_invites))
- $mysql_query_string .= " OR";
- }
- $mysqli_conn->query($mysql_query_string);
- }
- }
- else
- {
- if(isset($_GET["communityid"]))
- {
- //Can't invite more today, queueing
- $mysqli_conn->query("INSERT INTO queued_players (communityid) VALUES(\"".$mysqli_conn->real_escape_string($_GET["communityid"])."\")");
- }
- }
- //Close database connection
- $mysqli_conn->close();
- //Saving plugin info
- //New session
- if($invites_sofar == 0)
- $time_of_first = time();
- $invites_sofar += $invites_now;
- file_put_contents("autoinvite.txt", $invites_sofar."\n".$steam_cookie."\n".$time_of_first);
- function invite_player($inviter, $invitee, $group, $steam_cookie)
- {
- $query_string = "?type=groupInvite&inviter=".$inviter."&invitee=".$invitee."&group=".$group;
- $steam_invite = curl_init();
- curl_setopt($steam_invite, CURLOPT_URL, "http://steamcommunity.com/actions/GroupInvite".$query_string);
- curl_setopt($steam_invite, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($steam_invite, CURLOPT_HEADER, 1);
- curl_setopt($steam_invite, CURLOPT_COOKIE, "steamLogin=".$steam_cookie);
- $result = curl_exec($steam_invite);
- curl_close($steam_invite);
- return $result;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement