Cod4 Server Viewer Problem

Hippie
Hallole,
ich hab das jetzt Mal hier her geschrieben weil ich nicht wusste, ob's hierfür schon nen Thread gibt.

Mein Problem: Ich habe aus ein paar php Fetzen ausm Netz einen Serverviewer für Cod4 gebastelt (Beispiel findet Ihr hier)
Soweit klappt das alles - nur die Farbcodes (^1, ^2, usw.) werden nicht übernommen.
Vielleicht kann mir hier jemand helfen.

Hier ist der Code der index.php

Code einblendenCode angehängt. Klicke hier zum Ein-/Ausblenden

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
[PHP]
<?php 

// Server ip and port: 
if (!$server) { 
$server_ip = "46.38.232.42:28960";
$server_ip_clean ="46.38.232.42"; 
$server_port = "28960"; 
} else { 
$server = explode(":", $server); 
$server_ip = $server[0]; 
$server_port = $server[1]; 
} 

// Do NOT change anything below this line! 

// Creating the URL for the connection: 

$server_ip = "udp://" . $server_ip; 

// Open the connection: 
$connect = fsockopen($server_ip, $server_port, $errno, $errstr, 30); 

// Set the timeout: 
socket_set_timeout ($connect, 1, 000000); 

// Get the information from the server, and put it into the $output array: 

$send = "\xFF\xFF\xFF\xFFgetstatus\x00";  
fputs($connect, $send); 
fwrite ($connect, $send); 
$output = fread ($connect, 1); 
if (! empty ($output)) { 
   do { 
     $status_pre = socket_get_status ($connect); 
     $output = $output . fread ($connect, 1); 
     $status_post = socket_get_status ($connect); 
   } while ($status_pre[unread_bytes] != $status_post[unread_bytes]); 
}; 

// Close the connection: 
fclose($connect); 

// Select the variables from the $output array: 
$output = explode ("\\", $output); 

$max_index = array_search ("sv_maxclients", $output); 
$max_clients = $output[$max_index+1]; 

$max_index = array_search ("mapname", $output); 
$mapname = $output[$max_index+1];     

$max_index = array_search ("sv_hostname", $output); 
$hostname = $output[$max_index+1]; 

$max_index = array_search ("g_gametype", $output); 
$gametype = $output[$max_index+1]; 

$last_value = count($output) - 1; 
$players_string = $output[$last_value]; 
$players_string = explode("\"", $players_string); 

$get_first_ping = explode("\n", $players_string[0]); 
$players_string[0] = $get_first_ping[1]; 

$i = 1; 
$players = 0; 
while (count($players_string) != $i) { 
$i++; 
$i++; 
$players++; 
} 

// Create the image url: 
/*
if (substr($mapname, 0, 3) == "") { 
$picture_src = str_replace("dm/", "", $mapname); 
}
*/
$picture_src = "img/" . $mapname . ".jpg"; 

$mapname = substr($mapname, 3); 
$mapname = ucwords($mapname);  



// Convert the game type name to something a little more pleasing to the eye

if ($gametype == "sd"){$gametype = "Search & Destroy";} 	
elseif ($gametype == "dm"){$gametype = "Free For All Deathmatch";}
elseif ($gametype == "dom"){$gametype = "Domination";}
elseif ($gametype == "koth"){$gametype = "Headquarters";}
elseif ($gametype == "sab"){$gametype = "Sabotage";}
elseif ($gametype == "war"){$gametype = "TDM";}   


//First try to get the colors

  function check_color($text, $switch)
    {
        $clr = array ( // colors
        "\"#000000\"", "\"#DA0120\"", "\"#00B906\"", "\"#E8FF19\"", //  1
        "\"#170BDB\"", "\"#23C2C6\"", "\"#E201DB\"", "\"#FFFFFF\"", //  2
        "\"#CA7C27\"", "\"#757575\"", "\"#EB9F53\"", "\"#106F59\"", //  3
        "\"#5A134F\"", "\"#035AFF\"", "\"#681EA7\"", "\"#5097C1\"", //  4
        "\"#BEDAC4\"", "\"#024D2C\"", "\"#7D081B\"", "\"#90243E\"", //  5
        "\"#743313\"", "\"#A7905E\"", "\"#555C26\"", "\"#AEAC97\"", //  6
        "\"#C0BF7F\"", "\"#000000\"", "\"#DA0120\"", "\"#00B906\"", //  7
        "\"#E8FF19\"", "\"#170BDB\"", "\"#23C2C6\"", "\"#E201DB\"", //  8
        "\"#FFFFFF\"", "\"#CA7C27\"", "\"#757575\"", "\"#CC8034\"", //  9
        "\"#DBDF70\"", "\"#BBBBBB\"", "\"#747228\"", "\"#993400\"", // 10
        "\"#670504\"", "\"#623307\""                                // 11
        );

        if ($switch == 1) 
        { // colored string
            $search  = array (
            "/\^0/", "/\^1/", "/\^2/", "/\^3/",        //  1
            "/\^4/", "/\^5/", "/\^6/", "/\^7/",        //  2
            "/\^8/", "/\^9/", "/\^a/", "/\^b/",        //  3
            "/\^c/", "/\^d/", "/\^e/", "/\^f/",        //  4
            "/\^g/", "/\^h/", "/\^i/", "/\^j/",        //  5
            "/\^k/", "/\^l/", "/\^m/", "/\^n/",        //  6
            "/\^o/", "/\^p/", "/\^q/", "/\^r/",        //  7
            "/\^s/", "/\^t/", "/\^u/", "/\^v/",        //  8
            "/\^w/", "/\^x/", "/\^y/", "/\^z/",        //  9
            "/\^\//", "/\^\*/", "/\^\-/", "/\^\+/",    // 10
            "/\^\?/", "/\^\@/", "/\^</", "/\^>/",      // 11
            "/\^\&/", "/\^\)/", "/\^\(/", "/\^[A-Z]/", // 12
            "/\^\_/",                                  // 14
            "/&</", "/^(.*?)<\/font>/"                 // 15
            );

            $replace = array (
            "&<font color=$clr[0]>", "&<font color=$clr[1]>",   //  1
            "&<font color=$clr[2]>", "&<font color=$clr[3]>",   //  2
            "&<font color=$clr[4]>", "&<font color=$clr[5]>",   //  3
            "&<font color=$clr[6]>", "&<font color=$clr[7]>",   //  4
            "&<font color=$clr[8]>", "&<font color=$clr[9]>",   //  5
            "&<font color=$clr[10]>", "&<font color=$clr[11]>", //  6
            "&<font color=$clr[12]>", "&<font color=$clr[13]>", //  7
            "&<font color=$clr[14]>", "&<font color=$clr[15]>", //  8
            "&<font color=$clr[16]>", "&<font color=$clr[17]>", //  9
            "&<font color=$clr[18]>", "&<font color=$clr[19]>", // 10
            "&<font color=$clr[20]>", "&<font color=$clr[21]>", // 11
            "&<font color=$clr[22]>", "&<font color=$clr[23]>", // 12
            "&<font color=$clr[24]>", "&<font color=$clr[25]>", // 13
            "&<font color=$clr[26]>", "&<font color=$clr[27]>", // 14
            "&<font color=$clr[28]>", "&<font color=$clr[29]>", // 15
            "&<font color=$clr[30]>", "&<font color=$clr[31]>", // 16
            "&<font color=$clr[32]>", "&<font color=$clr[33]>", // 17
            "&<font color=$clr[34]>", "&<font color=$clr[35]>", // 18
            "&<font color=$clr[36]>", "&<font color=$clr[37]>", // 19
            "&<font color=$clr[38]>", "&<font color=$clr[39]>", // 20
            "&<font color=$clr[40]>", "&<font color=$clr[41]>", // 21
            "", "", "", "", "", "",                             // 22
            "", "</font><", "\$1"                               // 23
            );

            $ctext = preg_replace($search, $replace, $text);

            if ($ctext != $text)
	    {
                $ctext = preg_replace("/$/", "</font>", $ctext);
            }
	   
            return $ctext;
        }
        elseif ($switch == 2)
	{ // colored numbers
            if ($text <= 39)
	    {
	        $ctext = "<font color=$clr[7]>$text</font>";
	    }
	    elseif ($text <= 69)
	    {
	        $ctext = "<font color=$clr[5]>$text</font>";
            }
	    elseif ($text <= 129)
	    {
	        $ctext = "<font color=$clr[8]>$text</font>";
	    }	
            elseif ($text <= 399)
	    {
	        $ctext = "<font color=$clr[9]>$text</font>";
            }
            else
	    {
	        $ctext = "<font color=$clr[1]>$text</font>";
	    }

            return $ctext;
        }
    }    
	// scan the color tags of hostname
// hier kack' ich ab!!>>	$hostname['sv_hostname'] = $this->check_color($hostname['sv_hostname'], 1);


// Start the output: 
?>
<link href="css/viewer.css" rel="stylesheet" type="text/css">
          
<div id="gameserver">
  <div id="mappic"><img src="<?=$picture_src?>" border="0" alt="<?=$mapname?>"></div><br/>
<div id="data">
 <?php echo $hostname; ?> <br/><br/>
   <?php echo "IP:"; ?><a href="http://www.gametracker.com/server_info/<?php echo " 46.38.232.42"; ?>:<?php echo $server_port; ?>" target="_blank"><?php echo " 46.38.232.42"; ?></a><br />
               <?php echo "Map: "; ?> <?php echo $mapname; ?><br />
               <?php echo "Gamemode: "; ?> <?php echo $gametype; ?><br />

               <?php echo "Player: "; ?> <?php echo $players?> / <?php  echo $max_clients?></a>          
        
 </div></div>

[/PHP]



Ich bin für jede Anregung offen smile
Kelli
Nur überflogen, aber sv_hostname ist doch ein String, kein array und schon garnicht ein Objekt.

$host_colored = check_color($hostname, 1);
Oder?
Hippie
Danke für die Antwort.

Ich habe das Mal abgeändert - leider ohne Ergebnis...

lg

Hippie
Kelli

Code einblendenCode angehängt. Klicke hier zum Ein-/Ausblenden

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
<?php
 
// Server ip and port:
if (!$server) {
$server_ip = "46.38.232.42:28960";
$server_ip_clean ="46.38.232.42";
$server_port = "28960";
} else {
$server = explode(":", $server);
$server_ip = $server[0];
$server_port = $server[1];
}
 
// Do NOT change anything below this line!
 
// Creating the URL for the connection:
 
$server_ip = "udp://" . $server_ip;
 
// Open the connection:
$connect = fsockopen($server_ip, $server_port, $errno, $errstr, 30);
 
// Set the timeout:
socket_set_timeout ($connect, 1, 000000);
 
// Get the information from the server, and put it into the $output array:
 
$send = "\xFF\xFF\xFF\xFFgetstatus\x00"; 
fputs($connect, $send);
fwrite ($connect, $send);
$output = fread ($connect, 1);
if (! empty ($output)) {
do {
$status_pre = socket_get_status ($connect);
$output = $output . fread ($connect, 1);
$status_post = socket_get_status ($connect);
} while ($status_pre[unread_bytes] != $status_post[unread_bytes]);
};
 
// Close the connection:
fclose($connect);
 
// Select the variables from the $output array:
$output = explode ("\\", $output);
 
$max_index = array_search ("sv_maxclients", $output);
$max_clients = $output[$max_index+1];
 
$max_index = array_search ("mapname", $output);
$mapname = $output[$max_index+1];    
 
$max_index = array_search ("sv_hostname", $output);
$hostname = $output[$max_index+1];
 
$max_index = array_search ("g_gametype", $output);
$gametype = $output[$max_index+1];
 
$last_value = count($output) - 1;
$players_string = $output[$last_value];
$players_string = explode("\"", $players_string);
 
$get_first_ping = explode("\n", $players_string[0]);
$players_string[0] = $get_first_ping[1];
 
$i = 1;
$players = 0;
while (count($players_string) != $i) {
$i++;
$i++;
$players++;
}
 
// Create the image url:
/*
if (substr($mapname, 0, 3) == "") {
$picture_src = str_replace("dm/", "", $mapname);
}
*/
$picture_src = "img/" . $mapname . ".jpg";
 
$mapname = substr($mapname, 3);
$mapname = ucwords($mapname); 
 
 
 
// Convert the game type name to something a little more pleasing to the eye
 
if ($gametype == "sd"){$gametype = "Search & Destroy";}    
elseif ($gametype == "dm"){$gametype = "Free For All Deathmatch";}
elseif ($gametype == "dom"){$gametype = "Domination";}
elseif ($gametype == "koth"){$gametype = "Headquarters";}
elseif ($gametype == "sab"){$gametype = "Sabotage";}
elseif ($gametype == "war"){$gametype = "TDM";}  
 
 
//First try to get the colors
 
function check_color($text, $switch)
{
$clr = array ( // colors
"\"#000000\"", "\"#DA0120\"", "\"#00B906\"", "\"#E8FF19\"", //  1
"\"#170BDB\"", "\"#23C2C6\"", "\"#E201DB\"", "\"#FFFFFF\"", //  2
"\"#CA7C27\"", "\"#757575\"", "\"#EB9F53\"", "\"#106F59\"", //  3
"\"#5A134F\"", "\"#035AFF\"", "\"#681EA7\"", "\"#5097C1\"", //  4
"\"#BEDAC4\"", "\"#024D2C\"", "\"#7D081B\"", "\"#90243E\"", //  5
"\"#743313\"", "\"#A7905E\"", "\"#555C26\"", "\"#AEAC97\"", //  6
"\"#C0BF7F\"", "\"#000000\"", "\"#DA0120\"", "\"#00B906\"", //  7
"\"#E8FF19\"", "\"#170BDB\"", "\"#23C2C6\"", "\"#E201DB\"", //  8
"\"#FFFFFF\"", "\"#CA7C27\"", "\"#757575\"", "\"#CC8034\"", //  9
"\"#DBDF70\"", "\"#BBBBBB\"", "\"#747228\"", "\"#993400\"", // 10
"\"#670504\"", "\"#623307\""                                // 11
);
 
if ($switch == 1)
{ // colored string
$search  = array (
"/\^0/", "/\^1/", "/\^2/", "/\^3/",        //  1
"/\^4/", "/\^5/", "/\^6/", "/\^7/",        //  2
"/\^8/", "/\^9/", "/\^a/", "/\^b/",        //  3
"/\^c/", "/\^d/", "/\^e/", "/\^f/",        //  4
"/\^g/", "/\^h/", "/\^i/", "/\^j/",        //  5
"/\^k/", "/\^l/", "/\^m/", "/\^n/",        //  6
"/\^o/", "/\^p/", "/\^q/", "/\^r/",        //  7
"/\^s/", "/\^t/", "/\^u/", "/\^v/",        //  8
"/\^w/", "/\^x/", "/\^y/", "/\^z/",        //  9
"/\^\//", "/\^\*/", "/\^\-/", "/\^\+/",    // 10
"/\^\?/", "/\^\@/", "/\^</", "/\^>/",      // 11
"/\^\&/", "/\^\)/", "/\^\(/", "/\^[A-Z]/", // 12
"/\^\_/",                                  // 14
"/&</", "/^(.*?)<\/font>/"                 // 15
);
 
$replace = array (
"&<font color=$clr[0]>", "&<font color=$clr[1]>",   //  1
"&<font color=$clr[2]>", "&<font color=$clr[3]>",   //  2
"&<font color=$clr[4]>", "&<font color=$clr[5]>",   //  3
"&<font color=$clr[6]>", "&<font color=$clr[7]>",   //  4
"&<font color=$clr[8]>", "&<font color=$clr[9]>",   //  5
"&<font color=$clr[10]>", "&<font color=$clr[11]>", //  6
"&<font color=$clr[12]>", "&<font color=$clr[13]>", //  7
"&<font color=$clr[14]>", "&<font color=$clr[15]>", //  8
"&<font color=$clr[16]>", "&<font color=$clr[17]>", //  9
"&<font color=$clr[18]>", "&<font color=$clr[19]>", // 10
"&<font color=$clr[20]>", "&<font color=$clr[21]>", // 11
"&<font color=$clr[22]>", "&<font color=$clr[23]>", // 12
"&<font color=$clr[24]>", "&<font color=$clr[25]>", // 13
"&<font color=$clr[26]>", "&<font color=$clr[27]>", // 14
"&<font color=$clr[28]>", "&<font color=$clr[29]>", // 15
"&<font color=$clr[30]>", "&<font color=$clr[31]>", // 16
"&<font color=$clr[32]>", "&<font color=$clr[33]>", // 17
"&<font color=$clr[34]>", "&<font color=$clr[35]>", // 18
"&<font color=$clr[36]>", "&<font color=$clr[37]>", // 19
"&<font color=$clr[38]>", "&<font color=$clr[39]>", // 20
"&<font color=$clr[40]>", "&<font color=$clr[41]>", // 21
"", "", "", "", "", "",                             // 22
"", "</font><", "\$1"                               // 23
);
 
$ctext = preg_replace($search, $replace, $text);
 
if ($ctext != $text)
{
$ctext = preg_replace("/$/", "</font>", $ctext);
}
 
return $ctext;
}
elseif ($switch == 2)
{ // colored numbers
if ($text <= 39)
{
$ctext = "<font color=$clr[7]>$text</font>";
}
elseif ($text <= 69)
{
$ctext = "<font color=$clr[5]>$text</font>";
}
elseif ($text <= 129)
{
$ctext = "<font color=$clr[8]>$text</font>";
}  
elseif ($text <= 399)
{
$ctext = "<font color=$clr[9]>$text</font>";
}
else
{
$ctext = "<font color=$clr[1]>$text</font>";
}
 
return $ctext;
}
}   

$hostname = check_color($hostname, 1);
// Start the output:
?>
<link href="css/viewer.css" rel="stylesheet" type="text/css">
 
<div id="gameserver">
<div id="mappic"><img src="<?=$picture_src?>" border="0" alt="<?=$mapname?>"></div><br/>
<div id="data">
<?php echo $hostname; ?> <br/><br/>
<?php echo "IP:"; ?><a href="http://www.gametracker.com/server_info/<?php echo " 46.38.232.42"; ?>:<?php echo $server_port; ?>" target="_blank"><?php echo " 46.38.232.42"; ?></a><br />
<?php echo "Map: "; ?> <?php echo $mapname; ?><br />
<?php echo "Gamemode: "; ?> <?php echo $gametype; ?><br />
 
<?php echo "Player: "; ?> <?php echo $players?> / <?php  echo $max_clients?></a>         
 
</div></div>

Hippie
Vielen Dank, nu läufts wie es soll.
Ich habe in Sachen php noch einiges zu lernen smile

Nochmal danke!

Hippie



PS: Wenn Jemand am Cod4 Serverviewer interessiert ist, kurze PM an mich.