AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Fix needed (https://forums.alliedmods.net/showthread.php?t=74922)

shustas 07-27-2008 10:14

[HELP] Fix needed
 
*Solved*

Bugsy 07-27-2008 11:02

Re: [HELP] Fix needed
 
PHP Code:

new  enableplTag[33][33]
static 
BaseDir[64], FileDir[64], FileIP[64]
new 
bool:tagged[33]
new 
bool:connectshown[33];

public 
plugin_init() {
 
 
register_plugin(PLUGINVERSIONAUTHOR)
 
enable register_cvar("tag_by_ip""1")
 
}
 
public 
plugin_cfg() {
 
 
get_basedir(BaseDirCharsMax(BaseDir))
 
 
formatex(FileDirCharsMax(FileDir), "%s/TagByIp"BaseDir)
 
formatex(FileIPCharsMax(FileIP), "%s/Tag_By_Ip.cfg"FileDir)
 if(!
dir_exists(FileDir))
  
mkdir(FileDir)
 
 if(!
file_exists(FileIP))
  
write_file(FileIP";Add the beggining of Ip and prefered Tag: 127=[LOC]", -1)
 
}
public 
readfile(id) {
 
 new 
Ip[16], pIp[16], Tag[33], Buffer[64]
 static 
iFile
 
 get_user_ip
(idpIpCharsMax(Ip), 1)
 
 
iFile fopen(FileIP"rt")
 while(!
feof(iFile))
 {
  
fgets(iFileBufferCharsMax(Buffer));
 
  if((
Buffer[0] == ';') || (Buffer[0] == '/' && Buffer[1] == '/'))
   continue
 
  
strtok(BufferIpCharsMax(Ip), TagCharsMax(Tag), '='1)
 
  if(
ipmatch(pIpIp))
  {
   
tagged[id] = true
   copy
(plTag[id], CharsMax(Tag), Tag)
   
fclose(iFile)
   return 
PLUGIN_CONTINUE
  
}
 
 }
 
tagged[id] = false
 plTag
[id] = ""
 
fclose(iFile)
 return 
PLUGIN_CONTINUE
}
stock bool:ipmatch(pIp[], Ip[]) {
 
 new 
len
 
 len 
strlen(Ip) - 1
 
for(new i=0i<=leni++)
 {
  if(
pIp[i] != Ip[i])
  return 
false
 
}
 return 
true 
}
public 
client_putinserver(id) {
 
 if(!
get_pcvar_num(enable))
  return 
PLUGIN_HANDLED
 
 tagged
[id] = false
 plTag
[id] = ""
 
readfile(id)
 if(
tagged[id])
 {
  new 
OldName[32], TName[64]
  
get_user_name(idOldNameCharsMax(OldName))
 
  if( (
contain(OldNameplTag[id]) ==-1) && (connectshown[id] == false) )
  {
   
format(TNameCharsMax(TName), "%s%s"plTag[id], OldName)
   
set_user_info(id"name"TName
   
connectshown[id] = true;
  }
 }
 return 
PLUGIN_HANDLED
}
public 
client_disconnect(id) {
 
 
connectshown[id] = false;
 
tagged[id] = false
 plTag
[id] = ""
}
public 
client_infochanged(id) {
 
 if(!
get_pcvar_num(enable))
  return 
PLUGIN_HANDLED
 
 readfile
(id)
 if(
tagged[id])
 {
  new 
OldName[32], TName[64], NewName[64]
  
get_user_name(idOldNameCharsMax(OldName))
  
get_user_info(id"name"NewNameCharsMax(NewName))
 
  if(!
equali(NewNameOldName))
  {
   if(
contain(NewNameplTag[id]) ==-1)
   {
    
format(TNameCharsMax(TName), "%s%s"plTag[id], NewName)
    
set_user_info(id"name"TName)
   }
 
  }
 }
 
 return 
PLUGIN_HANDLED



shustas 07-27-2008 11:43

Re: [HELP] Fix needed
 
No man, connectshown[id] does not solve the problem.

Dr. Jan Itor 07-27-2008 11:57

Re: [HELP] Fix needed
 
whats the problem that it wont compile? if thats the case this compiles fine
Code:

new  enable, plTag[33][33]
static BaseDir[64], FileDir[64], FileIP[64]
new bool:tagged[33]
public plugin_init() {
 
 register_plugin(PLUGIN, VERSION, AUTHOR)
 enable = register_cvar("tag_by_ip", "1")
 
}
 
public plugin_cfg() {
 
 get_basedir(BaseDir, charsmax(BaseDir))
 
 formatex(FileDir, charsmax(FileDir), "%s/TagByIp", BaseDir)
 formatex(FileIP, charsmax(FileIP), "%s/Tag_By_Ip.cfg", FileDir)
 if(!dir_exists(FileDir))
  mkdir(FileDir)
 
 if(!file_exists(FileIP))
  write_file(FileIP, ";Add the beggining of Ip and prefered Tag: 127=[LOC]", -1)
 
}
public readfile(id) {
 
 new Ip[16], pIp[16], Tag[33], Buffer[64]
 static iFile
 
 get_user_ip(id, pIp, charsmax(Ip), 1)
 
 iFile = fopen(FileIP, "rt")
 while(!feof(iFile))
 {
  fgets(iFile, Buffer, charsmax(Buffer));
 
  if((Buffer[0] == ';') || (Buffer[0] == '/' && Buffer[1] == '/'))
  continue
 
  strtok(Buffer, Ip, charsmax(Ip), Tag, charsmax(Tag), '=', 1)
 
  if(ipmatch(pIp, Ip))
  {
  tagged[id] = true
  copy(plTag[id], charsmax(Tag), Tag)
  fclose(iFile)
  return PLUGIN_CONTINUE
  }
 
 }
 tagged[id] = false
 plTag[id] = ""
 fclose(iFile)
 return PLUGIN_CONTINUE
}
stock bool:ipmatch(pIp[], Ip[]) {
 
 new len
 
 len = strlen(Ip) - 1
 for(new i=0; i<=len; i++)
 {
  if(pIp[i] != Ip[i])
  return false
 }
 return true
}
public client_putinserver(id) {
 
 if(!get_pcvar_num(enable))
  return PLUGIN_HANDLED
 
 tagged[id] = false
 plTag[id] = ""
 readfile(id)
 if(tagged[id])
 {
  new OldName[32], TName[64]
  get_user_name(id, OldName, charsmax(OldName))
 
  if(contain(OldName, plTag[id]) ==-1)
  {
  format(TName, charsmax(TName), "%s%s", plTag[id], OldName)
  set_user_info(id, "name", TName)
  }
 }
 return PLUGIN_HANDLED
}
public client_disconnect(id) {
 
 tagged[id] = false
 plTag[id] = ""
}
public client_infochanged(id) {
 
 if(!get_pcvar_num(enable))
  return PLUGIN_HANDLED
 
 readfile(id)
 if(tagged[id])
 {
  new OldName[32], TName[64], NewName[64]
  get_user_name(id, OldName, charsmax(OldName))
  get_user_info(id, "name", NewName, charsmax(NewName))
 
  if(!equali(NewName, OldName))
  {
  if(contain(NewName, plTag[id]) ==-1)
  {
    format(TName, charsmax(TName), "%s%s", plTag[id], NewName)
    set_user_info(id, "name", TName)
  }
 
  }
 }
 
 return PLUGIN_HANDLED
}


shustas 07-27-2008 12:04

Re: [HELP] Fix needed
 
Im not talking about compile. Short intro. It reads from file the beggining of ip and asociated tag with it. Now everything is ok, except when i first connect and it reads my ip and assigns tag to my nick, it adds tag twice to my nick. Like [tag][tag]Nick

shustas 07-28-2008 12:14

Re: [HELP] Fix needed
 
Thanks Jan, but its not. I got no more ideas


All times are GMT -4. The time now is 05:38.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.