Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 23rd, 2012, 08:43 AM
GHBB GHBB is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 GHBB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 32 sec
Reputation Power: 0
Masterserver cs python help

Hello dear friends, I got to hand Masterserver for cs, interested in a couple of questions for him as I am in Python almost do not understand, the script displays a list of servers, but with a large number of servers starts to duplicate the connections as shown in the figure,
URL
With more than 16 to the ip address script has denied:
URL
I would like to increase the performance of the script and remove duplication in the list of servers, help or tell me.

The code:
Code:
#Masterserver v0.3 by Arsegg - 13.10.12
#(c) Arsegg, 2012
import socket,MySQLdb,ConfigParser,sqlite3,sys,thread,time

def serve_forever():
	host,port = cfg.get("OPTIONS","HOST"),cfg.getint("OPTIONS","PORT")
	s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
	s.bind((host,port))
	while 1:
		data,addr = s.recvfrom(1024)
		s.sendto(d,addr)
		
		
def load_servers():
	mode = cfg.get("OPTIONS","MODE")
	if mode == "FILE":
		file = cfg.get("FILE","FILE")
		srv = [i.strip("\n") for i in open(file)]
	elif mode == "MYSQL":
		host,name,user,password,table = cfg.get("MYSQL","HOST"),cfg.get("MYSQL","NAME"),cfg.get("MYSQL","USER"),cfg.get("MYSQL","PASSWORD"),cfg.get("MYSQL","TABLE")
		db = MySQLdb.connect(host=host,user=user,passwd=password,db=name)
		c = db.cursor()
		c.execute("SELECT * FROM %s"%table)
		srv = [i[0] for i in c.fetchall()]
	elif mode == "SQLITE":
		name = cfg.get("SQLITE","FILE")
		db = sqlite3.connect(name)
		c = db.cursor()
		c.execute("SELECT * FROM %s"%table)
		srv = [i[0] for i in c.fetchall()]
	global d
	_d = [0xFF,0xFF,0xFF,0xFF,0x66,0x0A]
	for i in srv:
		ip,port = i.split(":")
		ip = [int(j) for j in ip.split(".")]
		port = int(port)
		port = [port>>8&0xFF,port&0xFF]
		map(_d.append,ip)
		map(_d.append,port)
	_d += [0x00,0x00,0x00,0x00,0x00,0x00]
	d = "".join([chr(i) for i in _d])
	
	print "Masterserver v0.2\n\nServer list:"
	for i in srv:
		print "\t",i
		
		
try:
	cfg = ConfigParser.ConfigParser()
	cfg.read("ms.cfg")
	refresh = cfg.getfloat("OPTIONS","REFRESH")

	load_servers()
	thread.start_new_thread(serve_forever,())
	while 1:
		time.sleep(refresh)
		print "\n"
		load_servers()
except:
	print sys.exc_info()[0]



Config file:
Code:
[OPTIONS]
HOST = 0.0.0.0
PORT = 27010
#MODE = FILE
MODE = MYSQL
#MODE = SQLITE
REFRESH = 10

[FILE]
FILE = servers.txt

[MYSQL]
HOST = 
NAME = 
USER = 
PASSWORD = 
TABLE = 

[SQLITE]
FILE = servers.db


I'm not a script writer and respected Arsegg for which he thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Masterserver cs python help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap