Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 10-24-2004, 05:38 PM   #1 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 151
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Counter-Strike and Socket programming

I'm curious to learn how to communicate with a Counter-Strike server through sockets, in order to pull server information and to send rcon commands. Problem is I don't know anything about sockets really, and have no idea where to start

If you know of a good tutorial on sockets and/or happen to know where I can read about communicating with a Counter-Strike server through the web I would appreciate it.

I have looked through the MadQuery class and I really don't understand what I'm looking at...
__________________
Current Project
Redline is offline   Reply With Quote
Old 10-24-2004, 05:49 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
ah, nice to see you here josh.

madquery is about the only example i have for talking to a counter-strike server. i've modified it to connect to a cs:source server as well.

i haven't spent any time trying to send rcon commands, but it's definately possible.

this might help you: http://server.counter-strike.net/php...evelopment.php
__________________
Mike
sde is offline   Reply With Quote
Old 10-25-2004, 01:33 PM   #3 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 151
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Wow that class is exactly what I needed! That's going to allow me to do sooo much...wow

Ok, I'm having a little trouble with one of the functions. The ServerMaps function is supposed to return a multidimensional array with a list of the maps on the server right? Well, it returns a totally empty variable! I don't understand why...

Here is the ServerMaps function straight from the class

PHP Code:
  //Get all maps in all directories
  
function ServerMaps($pagenumber 0)
  {
    
//If there is no open connection return false
    
if(!$this->connected)
      return 
$this->connected;

    
//Get list of maps
    
$maps $this->RconCommand("maps *"$pagenumber);

    
//If there is no open connection return false
    //If there is bad rcon password return "Bad rcon_password."
    
if(!$maps || trim($maps) == "Bad rcon_password.")
      return 
$maps;

    
//Split Maplist in rows
    
$line explode("\n"$maps);
    
$count sizeof($line) - 4;

    
//format maps
    
for($i 0$i <= $count$i++)
    {
      
$text $line[$i];

      
//at directory output sorted map list
      
if(strstr($text"Dir:"))
      {
        
//reset counter
        
$mapcount 0;

        
//parse directory name
        
$directory strstr($text" ");

      } 
//if(strstr($text, "Dir:"))

      
else if(strstr($text"(fs)"))
      {
        
//parse mappath
        
$mappath strstr($text" ");

        
//parse mapname
        //if no "/" is included in the "maps * " result
        
if(!($tmpmap strrchr($mappath"/")))
          
$tmpmap $mappath;

        
//parse mapname without suffix (.bsp)
        
$result[$directory][$i] = substr($tmpmap1strpos($tmpmap".") - 1);

      } 
//else if(strstr($text, "(fs)"))

    
//for($i = 1; $i <= $count; $i++)


    //return formatted result
    
return $result;

  } 
//function ServerMaps() 
The way I am calling the function is this

PHP Code:
$server = new Rcon(); // Initiate class
.//Connection script
.
.
.
$maps $server->ServerMaps();

$check is_array($maps// Returns False 
$maps returns from the ServerMaps function totally null, and I can't figure out why. However I am able to pull server information and send rcon commands, so the connection is definately there
__________________
Current Project
Redline is offline   Reply With Quote
Old 10-25-2004, 03:20 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
http://ocsclan.com/rcon/

i just modified the logic of that function a bit .. now in the loop, if it finds a .bsp file, it adds it to the map array.

most of the for loop is commented out now .. this should work:
PHP Code:
  //Get all maps in all directories
  
function ServerMaps($pagenumber 0)
  {
    
//If there is no open connection return false
    
if(!$this->connected)
      return 
$this->connected;

    
//Get list of maps
    
$maps $this->RconCommand("maps *"$pagenumber);

    
//If there is no open connection return false
    //If there is bad rcon password return "Bad rcon_password."
    
if(!$maps || trim($maps) == "Bad rcon_password.")
      return 
$maps;

    
//Split Maplist in rows
    
$line explode("\n"$maps);
    
$count sizeof($line) - 4;

    
//format maps
    
for($i 0$i <= $count$i++)
    {
      if(
strstr($line[$i],".bsp"))
        
$result[]=str_replace(".bsp","",$line[$i]);
        
      
/*
      $text = $line[$i];

      //at directory output sorted map list
      if(strstr($text, "Dir:"))
      {
        //reset counter
        $mapcount = 0;

        //parse directory name
        $directory = strstr($text, " ");

      } //if(strstr($text, "Dir:"))

      else if(strstr($text, "(fs)"))
      {
        //parse mappath
        $mappath = strstr($text, " ");

        //parse mapname
        //if no "/" is included in the "maps * " result
        if(!($tmpmap = strrchr($mappath, "/")))
          $tmpmap = $mappath;

        //parse mapname without suffix (.bsp)
        $result[$directory][$i] = substr($tmpmap, 1, strpos($tmpmap, ".") - 1);

      } //else if(strstr($text, "(fs)"))
      */

    
//for($i = 1; $i <= $count; $i++)


    //return formatted result
    
return $result;

  } 
//function ServerMaps() 
__________________
Mike
sde is offline   Reply With Quote
Old 10-25-2004, 03:24 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
and here i've been doing everything the hard way .. lol, i never used this class before. that is nice =)
__________________
Mike
sde is offline   Reply With Quote
Old 10-25-2004, 03:56 PM   #6 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 151
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Wow, thanks sde, that function is a lot more...functional now

I'd still like to eventually learn how to write a class like that on my own, but I'm definately going to take advantage of this class.

I'm thinking about starting up a Clan web hosting service where I would host peoples websites, and offer tools like an Admin control panel where they can add multiple servers to their control panel, edit config files and send rcon commands.
__________________
Current Project
Redline is offline   Reply With Quote
Old 10-25-2004, 04:00 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
pretty cool .. i've thought about it since i've already developed a lot of automated clan management stuff, .. but there doesn't seem to be a lot of $ in hosting game servers unless you are going to go big and have quite a few servers at 1 colo. some companies prices are so low it is hard to compete.
__________________
Mike
sde is offline   Reply With Quote
Old 10-25-2004, 04:04 PM   #8 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 151
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Yeah I realise there isn't a whole lot of money in it, I'd be doing it more for the experience than anything. And if I was somehow able to earn enough money to pay the "rent" for my server and website for my clan, that'd be sweet.
__________________
Current Project
Redline is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 07:55 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting