mIRC Home    About    Download    Register    News    Help

Print Thread
#262499 08/02/18 11:59 AM
Joined: Feb 2018
Posts: 2
N
Nimes Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
N
Joined: Feb 2018
Posts: 2
Hi,

i wrote this bit of code yesterday, but i think it isnt good enough in terms of the way i worked with $regex

Im basically connecting to a Call of Duty 4 Server, to retrieve information like which map is being played right now, which gamemmode and such and it works. But maybe it is possible (im sure) to tidy up the those multiple regular expressions i used.

if you send "getstatus" to the server, i get a one-liner back which looks like this:

Quote:
/fs_game/0/version\1.7a\hostname\Random Server\Maxplayer\25\...\...\....\...\


Is it possible to use only one $regex (within the UDPREAD section) for all the information i need?

Thats the code:

Code:
on *:text:!cod*:#: {
  if (!%flood.cod) {
    set -u3 %flood.cod 1
    set %cod.chan $chan
    if ($3) { set %cod.search $3 }
    sockudp -k cod $cod.ip($2) $str($chr(255),4) $+ getstatus $chr(0)
  }
  else { halt }
}
 
alias codpost {
  msg %cod.chan **Server:** $rmcode(%ocod.hostname) $chr(124) **Version:** %ocod.version $chr(124) **Players:** $+($calc(%ocod.playercount - 2),/,%ocod.maxc) $chr(124) **Map:** %ocod.map $chr(124) **Gamemode:** %ocod.gametype
  unset %cod*
  unset %ocod*
}
 
on *:udpread:cod: {
  sockread %cod.tmp
  inc %ocod.playercount
  if (fs_game isin %cod.tmp) {
    if ($regex(%cod.tmp,.*\\(shortversion)\\(.*?)\\.*)) { set %ocod.version $regml(2) }
    if ($regex(%cod.tmp,.*\\(sv_maxclients)\\(.*?)\\.*)) { set %ocod.maxc $regml(2) }
    if ($regex(%cod.tmp,.*\\(sv_hostname)\\(.*?)\\.*)) { set %ocod.hostname $strip($regml(2)) }
    if ($regex(%cod.tmp,.*\\(uptime)\\(.*?)\\.*)) { set %ocod.uptime $regml(2) }
    if ($regex(%cod.tmp,.*\\(mapname)\\(.*?)\\.*)) { set %ocod.map  $regml(2) }
    if ($regex(%cod.tmp,.*\\(g_gametype)\\(.*?)\\.*)) { set %ocod.gametype $replace($regml(2),sd,Search & Destroy,war,Team Deathmatch,dm,Free for all,dom,Domination,koth,Headquarters,sab,Sabotage) }
    .timercod 1 1 codpost
  }
  if (%cod.search isin %cod.tmp) { msg %cod.chan $+(**,$gettok(%cod.tmp,3,32),**) - **Ping:** $gettok(%cod.tmp,2,32) - **Points:** $gettok(%cod.tmp,1,32) }
}
 
alias -l rmcode { return $remove($1-,^0,^1,^2,^3,^4,^5,^6,^7,8^,9) }
alias -l cod.ip { noop $regex($1,(.*?):(.*)) | return $regml(1) $regml(2) }



Would be glad for ur help. Ty in advance

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Could we get a full example of the response?

A caveat with the following code is to reference the variables, you'll need to specify them as they appear in the regex. For example, instead of using %ocod.version you'll need to use %ocod.shortversion
Code:
; ...
if (fs_game isin %cod.tmp && $regex(%cod.tmp, /\\(shortversion|sv_maxclients|sv_hostname|uptime|mapname|g_gametype)\\([^\\\/]+)/g)) {
  var %idx  = 0
  var %idx2 = 1
  var %end  = $regml(0)
  while (%idx < %end) {
    inc %idx
    inc %idx2
    
    if ($regml(%idx2) == g_gametype) {
      set %ocod.g_gametype = $replace($regml(%idx2), sd, Search & Destroy, war, Team Deathmatch, dm, Free for all, dom, Domination, koth, Headquarters, sab, Sabotage)
    }
    else {
      set %ocod. [ $+ [ $regml(%idx) ] ] $regml(%idx2)
    }
  }
  .timercod 1 1 codmsg
}
elseif (%cod.search isin %cod.tmp) {
  ; ...
}
; ...

Last edited by FroggieDaFrog; 08/02/18 01:21 PM.

I am SReject
My Stuff
Joined: Feb 2018
Posts: 2
N
Nimes Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
N
Joined: Feb 2018
Posts: 2
Yeah i understand, i could use your code and implement in mine. Firstly thank you for the bit of code, it actually helps alot.

A full response would look like this:

Quote:
ÿÿÿÿstatusResponse
\type\-1\sv_maxclients\30\fs_game\mods/nk_sniperx\version\CoD4 X 1.8 linux-i386 build 2055 May 2 2017\shortversion\1.8\build\2055\sv_floodprotect\4\sv_maxRate\25000\sv_voice\0\sv_maxPing\0\sv_minPing\0\sv_hostname\^0Night ^7Knights ^1SniperX ^2|| ^5Night^1-^5Knights^1.us \_CoD4 X Site\http://cod4x.me\protocol\17\sv_privateClients\0\sv_disableClientConsole\0\g_mapStartTime\Thu Feb 8 14:37:31 2018\uptime\9 days\g_gametype\sd\mapname\mp_crossfire\sv_pure\1\_B3\B3 v1.10.9^7[^1Custom^7] ^3By ^5$^6.^5W^6.^5@^6.^5T\gamename\Call of Duty 4\g_compassShowEnemies\0
75 56 "Dragontear"
20 246 "Gayya"
0 212 "DARK RIDER"
0 -1 "Alawi"
5 177 "I am Noob"
25 41 "Zagy"
35 132 "gopS"
0 53 "Dr. Acula!@mp3"
35 162 "john cena"
45 177 "G a Y "
40 109 "Freed0m4IRAN"


Everything below that one-liner is the count of the players playing on the server in that moment and obviously can change.

i Forgot to mention that that code only works on mIRC 6.35 - doesnt work on /.xx - UTF-8? I dont know.

Last edited by Nimes; 08/02/18 01:55 PM.

Link Copied to Clipboard