<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>IronPython for ASP.NET</title><link>http://forums.asp.net/1098.aspx</link><description>Discussions/Questions about IronPython for ASP.NET</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Strange errors on this script</title><link>http://forums.asp.net/thread/2685032.aspx</link><pubDate>Wed, 15 Oct 2008 16:56:27 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2685032</guid><dc:creator>Juba_PornBorn</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2685032.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1098&amp;PostID=2685032</wfw:commentRss><description>Hello, Im doing my first IP script and I&amp;#39;m getting really weird mistake I don&amp;#39;t understand how to solve.

Here&amp;#39;s the code and the errors I get:

1&amp;gt; 2 form windows and system tray icons show up

2&amp;gt; Button does not work and sometimes it shows this message on press:

&lt;font face="Lucida Console" size="2"&gt;startcheck[] has 2 arguments, none given&lt;/font&gt;

I haven&amp;#39;t defined arguments for startcheck.

3&amp;gt; Can&amp;#39;t get values from the variables inside the class in the script

Here&amp;#39;s the script:
&lt;font face="Lucida Console" size="2"&gt;&amp;#39;&amp;#39;&amp;#39; Script by Juba_PornBorn, Open Source Cod4 Tool Project, To donate or any kind of support: server_help@hotmail.co.uk Oficial web Page: uadminsdevenezuela.co.nr&amp;#39;&amp;#39;&amp;#39;

import os
import os.path
import socket
import cPickle
from threading import Timer
import clr
clr.AddReference(&amp;#39;System&amp;#39;)
clr.AddReference(&amp;#39;System.Windows.Forms&amp;#39;)
clr.AddReference(&amp;#39;System.Drawing&amp;#39;)
from System import *
from System.Windows.Forms import *
from System.Drawing import *

name_saver = {}
username = &amp;#39;none&amp;#39;
martyrdom = &amp;#39;frag_grenade_short_mp&amp;#39;
noob_tube = &amp;#39;gl_weapon_mp&amp;#39;
host = &amp;#39;localhost&amp;#39;
#value to check if new line is written
checkline = 0
#tray icon on logcheck loop on else turn of
tray_on = 0

class MyForm(Form):
    def __init__(self):
        self.MaximizeBox = 0
        self.MinimizeBox = 1
        self.ShowInTakbar = 0
        self.GetStayOnTop = 0
        self.FormBorderStyle = FormBorderStyle.Sizable
        self.Size = Size(546, 381)
        self.Text = &amp;quot;COD4 Warning System&amp;quot;
        
        image = Bitmap(Application.StartupPath + &amp;#39;\picturebox3img.jpg&amp;#39;)
        self.BackgroundImage = image

        self.button1 = Button(Text=&amp;#39;Start Check&amp;#39;, Location=Point(448,320), Size=Size(75, 23))
        self.button1.BackColor = Color.FromArgb(167, 166, 170)
        self.button1.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.button1.Cursor = Cursors.Default
        self.Controls.Add(self.button1)

        self.checkbox1 = CheckBox(Text=&amp;#39;Noob Tube (Granade Launcher)&amp;#39;, Location=Point(24,24), Size=Size(184, 19))
        self.checkbox1.Checked = True
        self.checkbox1.BackColor = Color.FromArgb(255, 255, 255)
        self.checkbox1.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.checkbox1.Cursor = Cursors.Default
        self.checkbox1.BackColor = Color.Transparent
        self.Controls.Add(self.checkbox1)

        self.checkbox2 = CheckBox(Text=&amp;#39;Martyrdom&amp;#39;, Location=Point(24,56), Size=Size(168, 22))
        self.checkbox2.Checked = True
        self.checkbox2.BackColor = Color.FromArgb(255, 255, 255)
        self.checkbox2.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.checkbox2.Cursor = Cursors.Default
        self.checkbox2.BackColor = Color.Transparent
        self.Controls.Add(self.checkbox2)

        self.textbox5 = TextBox(Text=&amp;#39;Insert game_mp.log direction here...&amp;#39;, Location=Point(224,24), Size=Size(288, 20))
        self.textbox5.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox5.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox5.Cursor = Cursors.Default
        self.Controls.Add(self.textbox5)

        self.textbox2 = TextBox(Text=&amp;#39;1&amp;#39;, Location=Point(10,104), Size=Size(20, 20))
        self.textbox2.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox2.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox2.Cursor = Cursors.Default
        self.Controls.Add(self.textbox2)

        self.textbox3 = TextBox(Text=&amp;#39;1&amp;#39;, Location=Point(10,144), Size=Size(20, 20))
        self.textbox3.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox3.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox3.Cursor = Cursors.Default
        self.Controls.Add(self.textbox3)

        self.label1 = Label(Text=&amp;#39;Max Warnings on Martydom before kick&amp;#39;, Location=Point(40,144), Size=Size(238, 17))
        self.label1.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.label1.Cursor = Cursors.Default
        self.label1.BackColor = Color.Transparent
        self.Controls.Add(self.label1)

        self.label2 = Label(Text=&amp;#39;Max Warnings on Noob Tube before kick&amp;#39;, Location=Point(40,104), Size=Size(238, 17))
        self.label2.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.label2.Cursor = Cursors.Default
        self.label2.BackColor = Color.Transparent
        self.Controls.Add(self.label2)

        self.textbox4 = TextBox(Text=&amp;#39;20&amp;#39;, Location=Point(314,104), Size=Size(25, 20))
        self.textbox4.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox4.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox4.Cursor = Cursors.Default
        self.Controls.Add(self.textbox4)

        self.label3 = Label(Text=&amp;#39;Time in minutes to save to Database&amp;#39;, Location=Point(344,96), Size=Size(140, 34))
        self.label3.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 9)
        self.label3.Cursor = Cursors.Default
        self.label3.BackColor = Color.Transparent
        self.Controls.Add(self.label3)

        self.textbox10 = TextBox(Text=&amp;#39;20&amp;#39;, Location=Point(314,144), Size=Size(25, 20))
        self.textbox10.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox10.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox10.Cursor = Cursors.Default
        self.Controls.Add(self.textbox10)

        self.label4 = Label(Text=&amp;#39;PunkBuster Temp Ban time in minutes&amp;#39;, Location=Point(344,136), Size=Size(100, 31))
        self.label4.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 9)
        self.label4.Cursor = Cursors.Default
        self.label4.BackColor = Color.Transparent
        self.Controls.Add(self.label4)

        self.textbox6 = TextBox(Text=&amp;#39;password&amp;#39;, Location=Point(16,208), Size=Size(100, 20))
        self.textbox6.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox6.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox6.Cursor = Cursors.Default
        self.Controls.Add(self.textbox6)

        self.label5 = Label(Text=&amp;#39;Rcon Password&amp;#39;, Location=Point(16,192), Size=Size(100, 23))
        self.label5.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.label5.Cursor = Cursors.Default
        self.label5.BackColor = Color.Transparent
        self.Controls.Add(self.label5)

        self.textbox7 = TextBox(Text=&amp;#39;28960&amp;#39;, Location=Point(136,208), Size=Size(100, 20))
        self.textbox7.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox7.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox7.Cursor = Cursors.Default
        self.Controls.Add(self.textbox7)

        self.label6 = Label(Text=&amp;#39;Server Port&amp;#39;, Location=Point(136,192), Size=Size(134, 17))
        self.label6.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.label6.Cursor = Cursors.Default
        self.label6.BackColor = Color.Transparent
        self.Controls.Add(self.label6)

        self.textbox8 = TextBox(Text=&amp;#39;%s is going to get kicked if noob tube is used again...&amp;#39;%username, Location=Point(16,264), Size=Size(340, 20))
        self.textbox8.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox8.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox8.Cursor = Cursors.Default
        self.Controls.Add(self.textbox8)

        self.label7 = Label(Text=&amp;#39;Warning message for noob tube&amp;#39;, Location=Point(16,248), Size=Size(298, 17))
        self.label7.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.label7.Cursor = Cursors.Default
        self.label7.BackColor = Color.Transparent
        self.Controls.Add(self.label7)

        self.textbox9 = TextBox(Text=&amp;#39;%s is going to get kicked if Martyrdom is used again...&amp;#39;%username, Location=Point(16,320), Size=Size(340, 20))
        self.textbox9.BackColor = Color.FromArgb(255, 255, 255)
        self.textbox9.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.textbox9.Cursor = Cursors.Default
        self.Controls.Add(self.textbox9)

        self.label11 = Label(Text=&amp;#39;Warning message for Martyrdom&amp;#39;, Location=Point(16,304), Size=Size(298, 17))
        self.label11.Font = Font(&amp;#39;Microsoft Sans Serif&amp;#39;, 8)
        self.label11.Cursor = Cursors.Default
        self.label11.BackColor = Color.Transparent
        self.Controls.Add(self.label11)
        
        self.initNotifyIcon()
        self.Resize += self.ResizeForm
        
    def initNotifyIcon(self):
        self.notifyIcon = NotifyIcon()
        self.notifyIcon.Icon = Icon(Application.StartupPath + &amp;#39;\cod4.ico&amp;#39;)
        self.notifyIcon.Visible = True
        self.notifyIcon.MouseDoubleClick += self.DoubleClickOnTrayIcon
        
    def ResizeForm(self, s, e):
        if self.WindowState == FormWindowState.Minimized:
            self.notifyIcon.Visible = True
            self.Visible = False
        
    def DoubleClickOnTrayIcon(self, s, e):
        if e.Button == MouseButtons.Left:
            self.Visible = True
            if self.WindowState == FormWindowState.Minimized:
                self.WindowState = FormWindowState.Normal
                self.notifyIcon.Visible = False
                
def StartCheckButton(sender, eventArgs):
    sender += eventArgs
    
def startcheck():
    global savedb, rcon_password, server_port, active_noobtube, active_martyrdom, minutes_kick_variable, warning_counter_tube, warning_counter_marty, game_or_mod_path, save_database, noob_text, marty_text
    
    # timer of saving database
    savedb = Timer(save_database * 60, savedatabase)
    savedb.start()
    
    #check form variables
    rcon_password = values.textbox6.Text
    server_port = values.textbox7.Text
    active_noobtube = values.checkbox1.Checked
    active_martyrdom = values.checkbox2.Checked
    minutes_kick_variable = values.textbox10.Text #In the form corresponds to the 20 minute Punkbuster variable 
    warning_counter_tube = values.textbox2.Text # Number of times player is warned before kick in the form corresponds to Max warnings Tube
    warning_counter_marty = values.textbox3.Text # Number of times player is warned before kick in the form corresponds to Max warnings Martydom 
    game_or_mod_path = values.textbox5.Text #test path
    save_database = values.textbox4.Text #time in minutes wich saves cPickle database of users
    noob_text = values.textbox8.Text
    marty_text = values.textbox9.Text
    
    # start logcheck loop
    tray_on = 1
    
    #Close form window and open system tray button
    values.WindowState = FormWindowState.Minimized
    test_socket()
    loaddatabase()
    openlogexists()
    
def socketconnect(cmd):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.settimeout(5)
        s.connect((host, server_port))
        packet = &amp;#39;&amp;#255;&amp;#255;&amp;#255;&amp;#255;rcon &amp;quot;%s&amp;quot; %s
&amp;#39; %(rcon_password, cmd)
        while len(packet) &amp;gt; 0:
            c = s.send(packet)
            packet = packet[c:]
        sleep(1)
        message = s.recv(2048)
        s.close()
        return message
    except ArgumentException:
        MessageBox.Show(&amp;quot;Could not connect to Server&amp;quot;, &amp;quot;&amp;quot;,MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

def test_socket():
    socketconnect(&amp;#39;status&amp;#39;)

def openlogexists():
    #complete path to games_mp.log
    global lastline
    global checkline
    global size
    try:
        logfile = open(game_or_mod_path, &amp;#39;r&amp;#39;)
        size = os.path.getsize(game_or_mod_path)
        lineList = logfile.readlines()
        lastline = lineList[-1]
        logfile.close()
    except ArgumentException:
        # to print on an error box
        MessageBox.Show(&amp;quot;Log %s not found&amp;quot; %game_or_mod_path , &amp;quot;&amp;quot;,MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        
    # check if line is still the same
    if lastline:
        if checkline != lastline:
            checkline = lastline
            checkcounters()
            logcheck()
            #start loop here on log check  or wait until the logcheck function ends and wait a second or 2 and start it again
            
def logcheck():
    global size
    global lastline
    
    logfile = open(game_or_mod_path, &amp;#39;r&amp;#39;)
    logfile.seek(size)
    lineList = logfile.readlines()
    lastline = lineList[-1]
    if lastline:
        if checkline != lastline:
            checkline = lastline
            size = os.path.getsize(game_or_mod_path)
            newlenght = len(lineList) - 1
            x = -1
            while x &amp;lt; newlenght:
                x += 1
                lastline = lineList[x]
                lastline
                checkcounters()
            sleep(5) # give a 5 second space between each check    
            if tray_on == 1:
                logcheck() #perform a loop on logcheck

def getname(lastline):
    #get username from lastline
    all_sentence = lastline.split(&amp;quot;;&amp;quot;)
    if &amp;#39;allies&amp;#39; in all_sentence:
        all_sentence.remove(&amp;#39;allies&amp;#39;)
    if &amp;#39;axis&amp;#39; in all_sentence:
        all_sentence.remove(&amp;#39;axis&amp;#39;)
    username = all_sentence[8]
    return username

def loaddatabase():
    # warning database with names and number of times warned loaded on startcheck
    global db
    global name_saver
    
    try:
        db = open(Application.StartupPath + &amp;#39;\warningdatabase.db&amp;#39;, &amp;#39;r&amp;#39;)
        name_saver = cPickle.load(db)
        db.close()
    except ArgumentException:
        MessageBox.Show(&amp;quot;    Error Loading Database: 
 Check or Create warningdatabase.db in Aplication Folder&amp;quot; , &amp;quot;&amp;quot;,MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

def savedatabase():
    # saved in time defined in save_database
    global db
    global name_saver
    
    db = open(Application.StartupPath + &amp;#39;\warningdatabase.db&amp;#39;, &amp;#39;w&amp;#39;)
    cPickle.dump(name_saver, db)
    db.close()

def checkcounters():
    global lastline
    global username
    global name_saver
    
    if active_noobtube == &amp;quot;True&amp;quot;:
        #debug print &amp;quot;testcounters&amp;quot;
        if noob_tube in lastline:
          
            #get username from lastline
            getname(lastline)

            # check if player is in warning list
            if name_saver.has_key(str(username)):
                name_saver[str(username)][&amp;quot;kick_tube&amp;quot;] += 1
                
            else:
                name_saver[&amp;quot;name&amp;quot;] = str(username)
                name_saver[str(username)] ={&amp;#39;kick_tube&amp;#39;:0, &amp;#39;kick_marty&amp;#39;:0}

            if name_saver[str(username)][&amp;quot;kick_tube&amp;quot;] &amp;lt;= warning_counter_tube:
                # sockets messages here and preferably sentences are loaded from a ini supporting multiple language
                print &amp;quot;%s is about to be kicked for using noobtube!!!&amp;quot; %username
                socketconnect(noob_text)

            else:
                #here goes the sockets connection to send the pb_kick command
                socketconnect(cmd = &amp;#39;PB_SV_Kick %s %s &amp;quot;Kicked due to use of noob tube&amp;quot; | &amp;quot;No noob tube in the server ever!&amp;quot;&amp;#39;%(username, minutes_kick_variable))
    
    if active_martyrdom == &amp;quot;True&amp;quot;:
        if martyrdom in lastline:
            
            #get username from lastline
            getname(lastline)
            
            # check if player is in warning list
            if name_saver.has_key(str(username)):
                name_saver[str(username)][&amp;quot;kick_marty&amp;quot;] += 1
            else:
                name_saver[&amp;quot;name&amp;quot;] = str(username)
                name_saver[str(username)] = {&amp;#39;kick_tube&amp;#39;:0, &amp;#39;kick_marty&amp;#39;:0}

            if name_saver[str(username)][&amp;quot;kick_marty&amp;quot;] &amp;lt;= warning_counter_marty:
                print &amp;quot;%s is about to be kicked for using martyrdom!!!&amp;quot; %username
                # sockets messages here
                socketconnect(marty_text)
                
            else:
                #here goes the sockets connection to send the pb_kick command
                socketconnect(cmd = &amp;#39;PB_SV_Kick %s %s &amp;quot;Kicked due to use of Martyrdom&amp;quot; | &amp;quot;No Martyrdom in the server ever!&amp;quot;&amp;#39;%(username, minutes_kick_variable))

StartCheckButton(MyForm().button1.Click, startcheck) 
values = MyForm()               
Application.EnableVisualStyles()
Application.Run(values)&lt;/font&gt;</description></item></channel></rss>