Author Topic: Text Based Linux Admin [source]  (Read 1122 times)

0 Members and 1 Guest are viewing this topic.

Offline Frenchie

  • Camper
  • ***
  • Posts: 358
  • SoldatHQ
Text Based Linux Admin [source]
« on: July 12, 2008, 07:43:00 pm »
Hey everyone,

I have just started learning python and this is my first app (it's extremely small/basic/silly)
It's a text based linux admin (basically exactly the same to using telnet) but it's got text highlighting. (atm basic cause of my lack of knowledge on regexp)

I would like feedback and any help towards it.

First time using threads, is it correct?
can anyone get player speech coloured?

Code: [Select]
import socket, thread, re

def readSock():
mess = mySocket.recv(1024)
if((mess.find('Time Left')!=-1) | (mess.find('Next map')!=-1) | (mess.find('File')!=-1)):
print '\033[37m' + mess + '\033[0m',
elif (re.match('\([0-9._%+-]\)', mess)):#Kills
print '\033[31m' + mess + '\033[0m',
#elif (re.match('\[[A-Z0-9._%+-]\]', mess)):#Player Speaking - Don't Know how to work it :(
#print '\033[35m' + mess + '\033[0m',
print mess,

mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
host = raw_input('Host>> ')
port = int(raw_input('Port>> '))
pw = str(raw_input('Pass>> '))
mySocket.connect ( ( host, port ) )
mySocket.send ( pw + '\r\n' )

reply= mySocket.recv(1024)
if(reply.find('Invalid password.')!=-1):
print 'Couldn\'t Connect to Server'
print reply

thread.start_new_thread(readSock, ())
while(1) :
data = raw_input()
if not data:
mySocket.send ( data + '\n')

Soldat Lobby Avec Players -New Release! - Updated AGAIN!