• 0

Need some help with a script.


Question

Hey guys, on my site DominateDominion.com I am trying to have a table that updates every day. Basically, I play a game called League of Legends and they have a map called Dominion. There is no ranked mode for dominion, but I was given some files that can get the players elo. I have a note pad where I type in the person's usernamer whos elo I want to find out, then I run a batch file, and open results.txt and it gives the players elo. The guy who gave me the files said all I need for it to update on my site automatically each day was a script where it dumps all the users from the site to a file, runs the batch file, then sends the update back to the server. So how could I do this? I'm don't know any programming or anything at all. Where should I start looking?

Link to comment
https://www.neowin.net/forum/topic/1057344-need-some-help-with-a-script/
Share on other sites

Recommended Posts

  • 0

@Digitalsnow and Alex

You find all the inforamtion you need here: http://na.leagueoflegends.com/board/showthread.php?t=1294429, if someone knows how to decode java, then convert it to x then it should make the job easier All i gathered from teh post was Java, irc, then riot games server which digital mentioned lol

  • 0

Well Digital I guess option A since it's easier. Sorry for the late reply, have been busy. But yeah, the contest is basically I want these stats to show up in a table from highest to lowest or something. A column with their name, another for their ELO, and another for their win/loss.

  • 0

What does each row in results.txt mean though? That's the info I'd need...

TheFeedski (Now:Bronze, S1:Bronze), RankedSolo5x5: 1254 [0W/0L], Dominion: 2189 [750W/566L], Normal: 624W/570L
Tootulz (Now:Bronze, S1:Bronze), RankedSolo5x5: 1271 [0W/0L], Dominion: 2199 [563W/429L], Normal: 516W/463L
TakinTheHeat (Now:Bronze, S1:Silver), RankedSolo5x5: 1275 [0W/0L], Dominion: 2033 [293W/260L], Normal: 968W/894L
Hugs From Momma, Dominion: 2164 [522W/459L], Normal: 228W/208L
Estufa (Now:Unranked, S1:Bronze), RankedSolo5x5: 1228 [2W/2L], Dominion: 2062 [443W/340L], Normal: 411W/377L
Dafe (Now:Bronze, S1:Silver), RankedSolo5x5: 1323 [1W/0L], Dominion: 1976 [219W/174L], Normal: 887W/824L
Gee4hire, Dominion: 2040 [281W/253L], Normal: 236W/236L
ZaberZ (Now:Bronze, S1:Gold), RankedSolo5x5: 1269 [0W/0L], Dominion: 2256 [547W/207L], Normal: 660W/553L
Forbiddian (Now:Bronze, S1:Unranked), RankedSolo5x5: 1330 [15W/10L], Dominion: 1911 [138W/90L], Normal: 194W/173L

Which do you want it ranking based on... RankedSolo5x5, Dominion, or Normal? Or the option for all 3? ...And what's an ELO?

  • 0

Ahh, I see what you're asking. I'll use mine for an example.

"TheFeedski (Now:Bronze, S1:Bronze), RankedSolo5x5: 1254 [0W/0L], Dominion: 2189 [750W/566L], Normal: 624W/570L"

The username is "TheFeedski". "Dominion 2189" is the elo, and the W/L beside the elo is the win/loss for the map Dominion. Those are the only three things I am wanting.

  • 0

This:

<?php

   echo '<table border="1" cellspacing="0"><th>Username</th><th>ELO</th><th>Wins</th><th>Losses</th><th>Ratio</th>';

   $fh = fopen('results.txt', 'r');
   while($line = fgets($fh))
   {
      // Remove any lines with no Dominion results
      if(strpos($line, 'Dominion: ') !== FALSE)
      {
         // Get the username - sometimes the line has '(Now:Bronze, S1:Silver)', sometimes not
         $username = (substr($line, 0, strpos($line, ' (Now:')) ?: substr($line, 0, strpos($line, ', ')));

         preg_match('/Dominion: (.*)L]/', $line, $scores);
         $elo = substr($scores[1], 0, strpos($scores[1], ' ['));
         $wins = substr($scores[1], strlen($elo)+2, strpos($scores[1], 'W/')-strlen($elo)-2);
         $losses = substr($scores[1], strlen($elo)+strlen($wins)+4);
         $ratio = round($wins/$losses, 2);

         echo "<tr><td>$username</td><td>$elo</td><td>$wins</td><td>$losses</td><td>$ratio</td></tr>";
      }
   }
   fclose($fh);

   echo '</table>';

?>

Produces this:

post-176093-0-91717300-1329763931.png

Name it whatever.php - upload it to /public_html - and browse to http://www.dominatedominion.com/whatever.php

Maybe someone else can work on making it rank in order? Just a little busy myself at the moment, otherwise I'll work on it a bit more later tonight/tomorrow :)

Also, it could probably be significantly improved with the use of RegEx, but sadly that's not my fort?.

  • 0

And with sortable headers:

<?php

   echo '<table border="1" cellspacing="0"><th>#</th><th>Username</th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=elo">ELO</a></th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=wins">Wins</a></th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=losses">Losses</a></th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=ratio">Ratio</a></th>';

   $i = 0;
   $fh = fopen('results.txt', 'r');
   while($line = fgets($fh))
   {
      // Remove any lines with no Dominion results
      if(strpos($line, 'Dominion: ') !== FALSE)
      {
         preg_match('/Dominion: (.*)L]/', $line, $scores);
         // For the username, sometimes the line has '(Now:Bronze, S1:Silver)', sometimes not
         $score[$i]['username'] = (substr($line, 0, strpos($line, ' (Now:')) ?: substr($line, 0, strpos($line, ', ')));
         $score[$i]['elo'] = substr($scores[1], 0, strpos($scores[1], ' ['));
         $score[$i]['wins'] = substr($scores[1], strlen($score[$i]['elo'])+2, strpos($scores[1], 'W/')-strlen($score[$i]['elo'])-2);
         $score[$i]['losses'] = substr($scores[1], strlen($score[$i]['elo'])+strlen($score[$i]['wins'])+4);
         $score[$i]['ratio'] = round($score[$i]['wins']/$score[$i]['losses'], 2);
         $i++;
      }
   }
   fclose($fh);

   function mysort($a, $b)
   {
      // Define the default sort here (currently 'elo')
      $sort = ($_GET['sort'] != 'elo' && $_GET['sort'] != 'wins' && $_GET['sort'] != 'losses' && $_GET['sort'] != 'ratio') ? 'elo' : $_GET['sort'];
      return strnatcmp($b[$sort], $a[$sort]);
   }

   usort($score, 'mysort');

   $i = 1;
   foreach($score as $score)
   {
      echo '<tr><td>' . $i . '</td><td>' . $score['username'] . '</td><td>' . $score['elo'] . '</td><td>' . $score['wins'] . '</td><td>' . $score['losses'] . '</td><td>' . $score['ratio'] . '</td></tr>';
      $i++;
   }

   echo '</table>';

?>

Like so:

post-176093-0-96044100-1329783674.png

I won't take offence if anyone wants to improve upon my code (obviously replace 'results.txt' with 'http://www.dominatedominion.com/results.txt' in the fopen) :)

  • Like 1
  • 0

Ok so here is the problem. So I use bluehost for my hosting, and I installed wordpress on my bluehost account. However, to edit my wordpress I don't even have to log into my bluehost. Is this going to be a problem? Can I still put this script like it is on wordpress? Because I don't just want a blank page with these numbers, I want to keep it looking like the rest of my site.

  • 0

Ok so here is the problem. So I use bluehost for my hosting, and I installed wordpress on my bluehost account. However, to edit my wordpress I don't even have to log into my bluehost. Is this going to be a problem? Can I still put this script like it is on wordpress? Because I don't just want a blank page with these numbers, I want to keep it looking like the rest of my site.

No problem... the code just needs wrapping in a Widget. Copy this into a file called leaderboard.php

<?php

   /*
   Plugin Name: Leaderboard
   Description: Dominion leaderboard
   Author: Alex Jones
   Version: 1.0.0
   Author URI: mailto:[email protected]
   */

   function widget_leaderboard()
   {
      echo '<table border="1" cellspacing="0"><th>#</th><th>Username</th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=elo">ELO</a></th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=wins">Wins</a></th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=losses">Losses</a></th><th><a href="' . $_SERVER['PHP_SELF'] . '?sort=ratio">Ratio</a></th>';

      $i = 0;
      $fh = fopen('results.txt', 'r');
      while($line = fgets($fh))
      {
         // Remove any lines with no Dominion results
         if(strpos($line, 'Dominion: ') !== FALSE)
         {
            preg_match('/Dominion: (.*)L]/', $line, $scores);
            // For the username, sometimes the line has '(Now:Bronze, S1:Silver)', sometimes not
            $score[$i]['username'] = (substr($line, 0, strpos($line, ' (Now:')) ?: substr($line, 0, strpos($line, ', ')));
            $score[$i]['elo'] = substr($scores[1], 0, strpos($scores[1], ' ['));
            $score[$i]['wins'] = substr($scores[1], strlen($score[$i]['elo'])+2, strpos($scores[1], 'W/')-strlen($score[$i]['elo'])-2);
            $score[$i]['losses'] = substr($scores[1], strlen($score[$i]['elo'])+strlen($score[$i]['wins'])+4);
            $score[$i]['ratio'] = round($score[$i]['wins']/$score[$i]['losses'], 2);
            $i++;
         }
      }
      fclose($fh);

      function mysort($a, $b)
      {
         // Define the default sort here (currently 'elo')
         $sort = ($_GET['sort'] != 'elo' && $_GET['sort'] != 'wins' && $_GET['sort'] != 'losses' && $_GET['sort'] != 'ratio') ? 'elo' : $_GET['sort'];
         return strnatcmp($b[$sort], $a[$sort]);
      }

      usort($score, 'mysort');

      $i = 1;
      foreach($score as $score)
      {
         echo '<tr><td>' . $i . '</td><td>' . $score['username'] . '</td><td>' . $score['elo'] . '</td><td>' . $score['wins'] . '</td><td>' . $score['losses'] . '</td><td>' . $score['ratio'] . '</td></tr>';
         $i++;
      }

      echo '</table>';
   }

   function leaderboard_init()
   {
      register_sidebar_widget(__('Leaderboard'), 'widget_leaderboard');
   }

   add_action("plugins_loaded", "leaderboard_init");

?>

Then upload it to /public_html/wp-content/plugins

Next go to your WP admin dashboard, click on Plugins, and click Activate on the new 'Leaderboard' plugin.

Now go to Appearance > Widgets, and drag the new widget into (e.g.) your sidebar.

And now you'll have something like this:

post-176093-0-29939200-1329889203_thumb.

Font sizes can be fiddled with afterwards. If you get a load of errors like 'fopen failed to open results.txt/fgets expects 2 parameters/blah blah blah', then you just need to change the path to results.txt in: $fh = fopen('results.txt', 'r');

Finally, I haven't just put my 'plugin author info' there to be anal - it's required by WP, otherwise the plugin won't show up.

As usual, any issues and we're here to help! :)

  • 0

You're awesome Alex. But when I clicked activate I got this error "Parse error: syntax error, unexpected ':' in /home2/dominau4/public_html/wordpress/wp-content/plugins/leaderboard.php on line 24".

Hey,

Nice easy error to fix. Quite simply, Bluehost must be running an old version of PHP on your server. Change this line:

$score[$i]['username'] = (substr($line, 0, strpos($line, ' (Now:')) ?: substr($line, 0, strpos($line, ', ')));

To this:

$score[$i]['username'] = (substr($line, 0, strpos($line, ' (Now:')) ? substr($line, 0, strpos($line, ' (Now:')) : substr($line, 0, strpos($line, ', ')));

This ?: That is short-hand for, if This is true, show me This, otherwise show me That... but support for the short-hand ternary was only added in PHP5. So instead, you have to duplicate This so it becomes This ? This : That... if any of that made sense :p

Anyways, make that change and you should be good to go! :D

One more thing: if you get a load of fopen/fgets errors (like I mentioned in my last post), change 'results.txt' to '../results.txt'

Alex

  • 0

Sorry for the late reply! I have been busy with test. It does work now that I changed that. But do you know if it is possible to have it in the middle instead of on the side?

Honestly, I don't know how to make a widget appear in the main content area. You could rewrite it so that it's a plugin instead of a widget, but that's a bit more work. Maybe one of the other WP experts could help you here... glad it works though! :)

Oh! Or is there a way I could add a field on the page that lets them type their username in to get added to the list? Can it be sent directly to players.txt somehow?

The best way to do this is to have a cron job setup on your Bluehost account to periodically dump all the usernames in the custom profile field of your forums. I can post the code you need to use, and how to set it up; but first I need these 2 bits of information.

-- 1)

Go to your phpBB admin panel

Click the Users and Groups tab

Then click Custom Profile Fields on the left side

Can you tell me what it says under 'Field identification'?

-- 2)

Still in your ACP, click the Maintenance tab

On the left side, under Database; click Backup

On the right you'll see a list of tables (Table select)... they'll all begin with a 'table prefix' (by default phpbb_)... can you tell me what it says before the underscore?

Alex :)

  • 0
Honestly, I don't know how to make a widget appear in the main content area. You could rewrite it so that it's a plugin instead of a widget, but that's a bit more work. Maybe one of the other WP experts could help you here... glad it works though! :) The best way to do this is to have a cron job setup on your Bluehost account to periodically dump all the usernames in the custom profile field of your forums. I can post the code you need to use, and how to set it up; but first I need these 2 bits of information. -- 1) Go to your phpBB admin panel Click the Users and Groups tab Then click Custom Profile Fields on the left side Can you tell me what it says under 'Field identification'? -- 2) Still in your ACP, click the Maintenance tab On the left side, under Database; click Backup On the right you'll see a list of tables (Table select)... they'll all begin with a 'table prefix' (by default phpbb_)... can you tell me what it says before the underscore? Alex :)

It says "summoner_name" "usual_play_time" and "preferred_champs" and before the _ is says "phpbb"

  • 0

Just wanted to write a quick post to let you know I'm gonna post the full info needed to get this working as soon as I can... my main dev PC crashed and having to restore everything slowly to another PC.

In the meantime if anyone else wants to write a PHP script to write the results of a MySQL query to a text file, then here's the start of it:

<?php

require_once('./forum/config.php');

$dh = mysqli_connect($dbhost, $dbuser, $dbpasswd, $dbname);
$res = mysqli_query($dh, "SELECT `pf_summoner_name` from `phpbb_profile_fields_data` WHERE `pf_summoner_name` != '' AND `pf_summoner_name` IS NOT NULL");

?>

This will then be called via a cron job as 'php -q /home2/dominau4/public_html/somefile.php'

  • 0


<?
require_once('./forum/config.php');


$fh = fopen('data.txt', 'w');

mysqli_connect($dbhost, $dbuser, $dbpasswd, $dbname);

$result = mysql_query("SELECT `pf_summoner_name` from `phpbb_profile_fields_data` WHERE `pf_summoner_name` != '' AND `pf_summoner_name` IS NOT NULL;");

while ($row = mysql_fetch_array($result)) {

$last = end($row);

foreach ($row as $item) {

fwrite($fh, $item);

if ($item != $last)
fwrite($fh, "\t");

}

fwrite($fh, "\n");
}

fclose($fh);
?>[/CODE]

Would that work?

  • 0


<?
require_once('./forum/config.php');


$fh = fopen('data.txt', 'w');

mysqli_connect($dbhost, $dbuser, $dbpasswd, $dbname);

$result = mysql_query("SELECT `pf_summoner_name` from `phpbb_profile_fields_data` WHERE `pf_summoner_name` != '' AND `pf_summoner_name` IS NOT NULL;");

while ($row = mysql_fetch_array($result)) {

$last = end($row);

foreach ($row as $item) {

fwrite($fh, $item);

if ($item != $last)
fwrite($fh, "\t");

}

fwrite($fh, "\n");
}

fclose($fh);
?>[/CODE]

Would that work?

I have no idea. :\

Alex left us! :(

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • State of Decay 2, Blasphemous 2, and more join Xbox Free Play Days by Pulasthi Ariyasinghe The latest Free Play Days offer has just kicked off, giving Xbox players the chance to try out a new selection of games over the weekend. The offerings this time aren't as massive as last weekend, but there are still major releases for Xbox players to jump into. This includes Undead Labs' post-apocalyptic title State of Decay 2, as well as two Team17-published titles. Two of the games being offered this time are available to all Xbox players without needing any kind of Game Pass subscription. In the fully free-to-play section, you can jump into State of Decay 2. The title is both an action survival title and a community builder, letting players choose a map, set up their base, and try to keep the growing zombie threat at bay. Cooperative play is available too. Don't forget that the studio is preparing a third entry for 2027. Next, Blasphemous 2 drops in for Metroidvania and Soulslike fans, where The Penitent One returns for another adventure. The title has tough combat with multiple weapon options, deadly traps to avoid, and platforming sequences requiring a lot of patience and timing. Keep in mind though that the offer does have a 5-hour time limit attached to it. Lastly, Xbox Game Pass Ultimate, Premium, and Essential members can now try out the WWII-set first-person shooter Hell Let Loose. The multiplayer game offers 50 vs 50 combat in massive maps, with infantry, tank, and artillery options available for players. Here are the announced games and the platforms they are available to play on: Hell Let Loose (Xbox Series X|S, PC) State of Decay 2: Juggernaut Edition (Xbox Series X|S, PC) Blasphemous 2 (Xbox Series X|S, Xbox One) To easily find the titles on Xbox consoles, first head to the Store, and then in the sidebar, find the Home section. In there, open the Subscriptions tab. The Free Play Days collection will show up in this area. This week's Free Play Days promotions will end on Sunday, June 11, at 11:59 pm PT.
    • Can we not have paperless office, like we was promised in the 80's
    • I actually laughed out loud in real life at the heading on this—whatever Microsoft is drinking, I want some of it.
    • Euro-Office must default to ODF to be considered "genuinely European", LibreOffice argues by David Uzondu Euro-Office is a web-based collaborative office suite that positions itself as a "European sovereign alternative" to American tech companies, backed by a coalition of developers including Nextcloud, IONOS, Abilian, BTactic, OpenProject, and, more recently, Tuta. The project officially went live a couple of days ago, but not before drawing heavy fire from LibreOffice developers, who called the marketing claim that Euro-Office represents the "first open-source office suite developed in Europe" a deceptive historical inaccuracy because projects like OpenOffice and LibreOffice existed decades earlier. Now that the project has launched, LibreOffice is back with another complaint, arguing that Euro-Office cannot consider itself "genuinely European" while it pushes proprietary Microsoft defaults on users. Euro-Office had promised to improve the OpenDocument Format (ODF) back in April, but the current release still plagues users with several technical failures. For instance, the suite lacks an admin setting to enforce ODF, and mobile editors completely block ODF saves, forcing files into Microsoft's OOXML formats. Some configurations force files into read-only mode, while editing frequently corrupts document formatting or erases data. LibreOffice thinks that merely supporting a format as an afterthought does not make you a sovereign alternative, as file formats are the battleground where" digital sovereignty is won or lost." The road to the first stable release of Euro-Office has been quite bumpy due to an aggressive public fallout with OnlyOffice, from which the coalition originally forked the project. OnlyOffice struck back by accusing the coalition of violating copyright terms under its AGPLv3 branding requirements by stripping the original branding anyway and forking the code. Getting Euro-Office up and running is a bit wonky (at least for non-technical users), as there is no direct installer to grab off the web. The easiest way we learnt is by using Docker. First, pull the official Euro-Office image from the GitHub Container Registry: docker pull ghcr.io/euro-office/documentserver:latest Then, run the container with active ports and a secure JWT token, enabling the test environment: docker run -i -t -d -p 8080:80 --restart=always -e EXAMPLE_ENABLED=true -e JWT_SECRET=my_secure_jwt_secret ghcr.io/euro-office/documentserver:latest And finally, open a web browser and go to the following address: http://localhost:8080 If you are running this on a remote server, replace localhost with your server's IP address. You will see the Euro-Office test page, where you can create new text documents, spreadsheets, or presentations directly in the browser. Image via Euro-Office Nextcloud promises that proper standalone desktop versions and mobile apps will arrive in a future release.
  • Recent Achievements

    • Week One Done
      FBSPL earned a badge
      Week One Done
    • One Year In
      Jim Dugan earned a badge
      One Year In
    • One Month Later
      Tommi118 earned a badge
      One Month Later
    • One Month Later
      sjbousquet earned a badge
      One Month Later
    • Week One Done
      sjbousquet earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      486
    2. 2
      PsYcHoKiLLa
      197
    3. 3
      +Edouard
      155
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      69
  • Tell a friend

    Love Neowin? Tell a friend!