ok, vielen dank, ich denke jetzt könnte es langsam funktionieren, lange genug probiert habe ichs ja
/edith: im normalen betrieb vor dem compilen DEBUG auf 0 setzen...
Code:
/*********************************************************
* An IP monitoring plugin - Version 0.8 *
*********************************************************
* *
* Name: plugin_rindy_chasecam *
* Author: Rinde (rinde@fiatnox.de) *
* Released: 28/01/03 *
* *
* *
* Version 0.8 *
* *
* - Initial release *
* *
*********************************************************/
/* Includes */
#include <plugin>
#include <adminlib>
/* Constants */
#define MAX_IP_LENGTH 22
#define DEBUG 1
/* Function Declarations */
forward csay(Text[MAX_TEXT_LENGTH]);
/* Global Variables */
new g_Version[] = "0.8";
new g_LANID[MAX_PLAYERS];
new g_IDs;
new g_Enabled;
/* Event Handlers */
public plugin_init() {
plugin_registerinfo("Rindes Forcechasecam Plugin","Sets mp_forcechasecam to 2 when players with the same ip are playing",g_Version);
return PLUGIN_CONTINUE;
}
public plugin_connect(HLUserName,HLIP,UserIndex) {
new UserName[MAX_NAME_LENGTH];
new Name[MAX_NAME_LENGTH];
new UserIP[MAX_IP_LENGTH];
new IP[MAX_IP_LENGTH];
new Text[MAX_TEXT_LENGTH];
new maxplayers = maxplayercount();
new i;
convert_string(HLIP,UserIP,MAX_IP_LENGTH);
if(strrchr(UserIP,':') != -1) UserIP[strrchr(UserIP,':')] = 0;
#if DEBUG == 1
new Logtext[MAX_TEXT_LENGTH];
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) User connected, index %i, IP %s",UserIndex,UserIP);
log(Logtext);
#endif
for(i=1;i<=maxplayers;i++) {
if(playerinfo(i,Name,MAX_NAME_LENGTH) == 1 && i != UserIndex) {
get_userIP(Name,IP,MAX_IP_LENGTH);
if(strrchr(IP,':') != -1) IP[strrchr(IP,':')] = 0;
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Checking User %s, index %i, IP %s",Name,i,IP);
log(Logtext);
#endif
if(strcmp(UserIP,IP) == 0) {
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) IP match: Users %i and %i, IPs %s and %s",UserIndex,i,UserIP,IP);
log(Logtext);
#endif
if(g_LANID[i] == 0) {
g_IDs++;
g_LANID[i] = g_IDs;
g_LANID[UserIndex] = g_IDs;
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Set LANID of players %i and %i to %i",UserIndex,i,g_IDs);
log(Logtext);
#endif
} else {
g_LANID[UserIndex] = g_LANID[i];
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Player %i already playing in LAN %i, adding player %i",i,g_LANID[i],UserIndex);
log(Logtext);
#endif
}
if(g_Enabled == 0) {
g_Enabled = 1;
setstrvar("mp_forcechasecam","2");
convert_string(HLUserName,UserName,MAX_NAME_LENGTH);
snprintf(Text,MAX_TEXT_LENGTH,"%s and %s are playing from the same LAN, mp_forcechasecam thus was set to 2",UserName,Name);
csay(Text);
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Set mp_forcechasecam to 2");
log(Logtext);
} else {
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Didn't set mp_forcechasecam, already set");
log(Logtext);
#endif
}
#if DEBUG == 1
i = 0;
#endif
break;
}
}
}
#if DEBUG == 1
if(i == 0) {
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) No match found for player %i",UserIndex);
log(Logtext);
}
#endif
return PLUGIN_CONTINUE;
}
public plugin_disconnect(HLUserName,UserIndex) {
new UserName[MAX_NAME_LENGTH];
new Text[MAX_TEXT_LENGTH];
new maxplayers = maxplayercount();
new i,j,k,l;
#if DEBUG == 1
new Logtext[MAX_TEXT_LENGTH];
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) User disconnected, index %i, LANID %i",UserIndex,g_LANID[UserIndex]);
log(Logtext);
#endif
if(g_Enabled == 1 && g_LANID[UserIndex] != 0) {
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Starting search");
log(Logtext);
#endif
for(i=1;i<=maxplayers;i++) {
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Checking player %i, LANID %i",i,g_LANID[i]);
log(Logtext);
#endif
if(i == UserIndex) {
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Canceled checking, player %i is disconnecting.",i);
log(Logtext);
#endif
continue;
} else if(g_LANID[UserIndex] == g_LANID[i]) {
j++;
k = i;
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Match: Player %i is in same LAN (%i) as player %i, %i total",i,g_LANID[i],UserIndex,j);
log(Logtext);
#endif
} else if(g_LANID[i] != 0) {
l++;
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Player %i is in another LAN (%i), %i total",i,g_LANID[i],l);
log(Logtext);
#endif
}
}
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Finished checking, found %i players on LAN %i, %i others",j,g_LANID[UserIndex],l);
log(Logtext);
#endif
g_LANID[UserIndex] = 0;
if(j == 1) {
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Player %i is the only player in LAN %i",k,g_LANID[k]);
log(Logtext);
#endif
g_LANID[k] = 0;
if(l == 0) {
g_Enabled = 0;
setstrvar("mp_forcechasecam","0");
convert_string(HLUserName,UserName,MAX_NAME_LENGTH);
snprintf(Text,MAX_TEXT_LENGTH,"%s disconnected, mp_forcechasecam thus was set back to 0",UserName);
csay(Text);
#if DEBUG == 1
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) No more LAN players found, setting mp_forcechasecam to 0");
log(Logtext);
} else {
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) %i LAN players still were found, proceeding",l);
log(Logtext);
#endif
}
#if DEBUG == 1
} else {
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) LAN %i still has %i players, proceeding",g_LANID[k]);
log(Logtext);
#endif
}
#if DEBUG == 1
} else {
snprintf(Logtext,MAX_TEXT_LENGTH,"(plugin_chasecam) Skipping search, not mp_forcechasecam od LANID of %i is 0",UserIndex);
log(Logtext);
#endif
}
return PLUGIN_CONTINUE;
}
csay(Text[MAX_TEXT_LENGTH]) {
new Name[MAX_NAME_LENGTH];
new maxplayers = maxplayercount();
new i;
#if DEBUG == 1
log(Text);
#endif
for(i=1;i<=maxplayers;i++) {
if(playerinfo(i,Name,MAX_NAME_LENGTH) == 1) {
messageex(Name,Text,print_pretty);
}
}
}