no idea to create a serverlist

how can i create a server-list to connect clients and let them choose what server they prefer? i used TCP to connect server and client but now i need servers add their ip to a server-list… i can’t use a server.exe as server because i haven’t a my own server… has anyone idea? i try with GET_HTTP and POST_HTTP but i have no result…

I’m sorry, I don’t understand what you are asking. The words you are using make sense, but the sentence doesn’t.

David

Here is what I think he is asking:

He wants to have mutli servers, all of which “sign in” to a web server, so when the client looks up a server off the website, it will see which ones are online.

For that sort of thing, I think you will certainly need to have your own server, with the ability to write custom code that runs on the server.

David

U could use a php based sign-in/sign-out script and place it on your webspace or u write an app and place it on a (v)server or u abuse the IRC protocol and setup your own IRC server.

I have a Master Server script using Py 2.6 (not panda). It was made by a fella for TGE. I hope it helps.

I dont have a full Python Client working with it, all I have is a shutdown packet sending script. Enjoy.

#Author: Andy Rollins
########################   C O N F I G U R A T I O N   ########################
port = 21567               # port number to run on
buf = 1024
game_server_timeout = 180  # Number of seconds after which time a server is removed from the list
verbose = True             # If set to True displays all available information
###############################################################################


from socket import *
import struct, time


#######################################
def str_2_num(in_str):
    return_num = 0
    multiplier = 1
    
    for c in in_str:
        return_num += ord(c) * multiplier
        multiplier *= 256
        
    return return_num

#######################################
def num_2_str(n):
    return_string = ''
    while n > 0:
        n, b = divmod(n, 256)
        return_string += chr(b) 
    return return_string

#######################################
def num_2_2byte_str(n):
    n, b = divmod(n, 256)
    n, b1 = divmod(n, 256)    
    return chr(b) + chr(b1)

#######################################
def send_server_list(list_request):
    packet_type = chr(8)
    flag = chr(0)
    server_count = len(g_server_list)
    print "Sending list data for ", server_count, " servers"
    addr = (list_request["client_ip"], list_request["client_port"])
    
    if server_count > 0:
        for index, list_item in enumerate(g_server_list):
            # Split the Ip address into seperate elements
            ip = list_item["IP"].split(".",3)
            
            response_packet = struct.pack("!2c i 2c 2s 4c 2s",
                                  packet_type,                      # Set to 8 for game server list query response
                                  flag,                             # ?? 
                                  list_request["packet_key"],       # packet key used in the query made
                                  chr(index),                       # packet index
                                  chr(server_count),                # total number of packets
                                  num_2_2byte_str(1),               # Count of how many servers there are to return
                                  chr(int(ip[0])), chr(int(ip[1])), chr(int(ip[2])), chr(int(ip[3])),   # IP Address split into 4 parts
                                  num_2_2byte_str(list_item["port"]))     # port number

            g_socket.sendto(response_packet, addr)

    else:
        # send back a packet to say there are no servers
        response_packet = struct.pack("!2c i 2c h", packet_type, flag,
                                  list_request["packet_key"], chr(0), chr(1), 0) 
    
        g_socket.sendto(response_packet, addr)


#######################################
def processListRequest(data):
    request_data = struct.unpack("!2ci2c", data[0:8])
    list_request["query_flags"] = request_data[1]
    list_request["packet_key"] = request_data[2]

    # Fetch the game type which is string held in our request data
    game_type_len =  ord(request_data[4])
    pos = 8 + game_type_len
    game_type = struct.unpack("!" + str(game_type_len) + "s", data[8:pos])
    list_request["game_type"] = game_type[0]

    # Fetch the mission type which is string held in our request data
    mission_type_len = ord(struct.unpack("c", data[pos : pos+1])[0])
    pos += 1
    mission_type = struct.unpack("!" + str(mission_type_len) + "s", data[pos:pos+mission_type_len])
    list_request["mission_type"] = mission_type[0]

    # Fetch the rest of the request data
    pos += mission_type_len
    request_data = struct.unpack("!2c 4s 4s 2c 2s c", data[pos:pos+15])
    list_request["min_players"] = ord(request_data[0])
    list_request["max_players"] = ord(request_data[1])
    list_request["region_mask"] = str_2_num(request_data[2])
    list_request["version"] = str_2_num(request_data[3])
    list_request["filter_flags"] = ord(request_data[4])
    list_request["max_bots"] = ord(request_data[5])
    list_request["min_cpu"] = str_2_num(request_data[6])
    list_request["buddy_count"] = ord(request_data[7])

    # Display the information to screen
    if verbose:
        print "    Game Type    : ", list_request["game_type"]
        print "    Mission Type : ", list_request["mission_type"]
        print "    Min Players  : ", list_request["min_players"]
        print "    Max Players  : ", list_request["max_players"]
        print "    Region Mask  : ", list_request["region_mask"]
        print "    Version      : ", list_request["version"]
        print "    Filter Flags : ", list_request["filter_flags"]
        print "    Max Bots     : ", list_request["max_bots"]
        print "    Min CPU      : ", list_request["min_cpu"]
        print "    Buddy Count  : ", list_request["buddy_count"]


#######################################
def processInfoResponse(data, server_ip, server_port):

    s = findServer(server_ip, server_port)
    if s > -1:
        g_server_list[s]["last_ping"] = time.time()
    else:
        g_server_list.append( {"IP" : packet_ip, "port" : packet_port, "last_ping" : time.time() })
    
    request_data = struct.unpack("!2c 2s 2s c", data[0:7])
    flags = ord(request_data[1])
    g_server_list[s]["session"] = str_2_num(request_data[2])
    key = str_2_num(request_data[3])

    # Fetch the game type which is string held in our request data
    game_type_len =  ord(request_data[4])
    pos = 7 + game_type_len
    game_type = struct.unpack("!" + str(game_type_len) + "s", data[7:pos])
    g_server_list[s]["game_type"] = game_type[0]

    # Fetch the mission type which is string held in our request data
    mission_type_len = ord(struct.unpack("c", data[pos : pos+1])[0])
    pos = pos + 1
    mission_type = struct.unpack("!" + str(mission_type_len) + "s", data[pos:pos+mission_type_len])
    g_server_list[s]["mission_type"] = mission_type[0]

    # Fetch the rest of the request data
    pos = pos + mission_type_len
    request_data = struct.unpack("!c 4s 4s 2c 4s c", data[pos:pos+16])
    g_server_list[s]["max_players"] = ord(request_data[0])
    g_server_list[s]["region_mask"] = str_2_num(request_data[1])
    g_server_list[s]["version"] = str_2_num(request_data[2])
    g_server_list[s]["filter_flags"] = ord(request_data[3])
    g_server_list[s]["num_bots"] = ord(request_data[4])
    g_server_list[s]["cpu_speed"] = str_2_num(request_data[5])
    g_server_list[s]["num_players"] = ord(request_data[6])

    if verbose:
        print "    Game type    : ", g_server_list[s]["game_type"]
        print "    Mission type : ", g_server_list[s]["mission_type"]
        print "    Number Bots  : ", g_server_list[s]["num_bots"]
        print "    Num players  : ", g_server_list[s]["num_players"]
        
    

#######################################
def findServer( ip_address, port_no):    
    for index, list_item in enumerate(g_server_list):
        if list_item["IP"] == ip_address and list_item["port"] == port_no:
            return index
        
    return -1  
        

#######################################
def processServers():
    for index, list_item in enumerate(g_server_list):
        if list_item["last_ping"] < time.time() - game_server_timeout:
            if verbose:
                print "Server Timed out IP:", g_server_list[index]["IP"], " Port:", g_server_list[index]["port"]
            del g_server_list[index]


###############################################################################
## MAIN CODE BLOCK    
###############################################################################
addr = ("",port)
g_socket = socket( AF_INET, SOCK_DGRAM)
g_socket.bind(addr)

run_server = True
g_server_list = []

try:
    while run_server:

        #g_socket.settimeout(5)
        data, client = g_socket.recvfrom(buf)
        packet_ip = client[0]
        packet_port = client[1]

        processServers()    # Updates the list of servers and removes any from the list that have timed out

        out_string = struct.unpack("c", data[0])
        request_type = ord(out_string[0])

        if request_type == 22:    # Heartbeat from a server
            print "Heartbeat from IP:", packet_ip, " Port:", packet_port
            pos = findServer(packet_ip, packet_port)

            if pos > -1:
                g_server_list[pos]["last_ping"] = time.time()
            else:
                g_server_list.append( {"IP" : packet_ip, "port" : packet_port, "last_ping" : time.time() })

            # Request Information from the game server
            response_packet = struct.pack("!c", chr(10))
            print "Sending Game Info Request IP:", packet_ip, " Port:", packet_port
            g_socket.sendto(response_packet, client)
            
        elif request_type == 6:   # Game server list request
            print "Gameserver list request from IP:", client[0], " Port:", client[1]
            list_request = {"client_ip" : packet_ip, "client_port" : packet_port}

            processListRequest(data)
            send_server_list(list_request)

        elif request_type == 12:
            print "Game Info response from IP: ", packet_ip, " port: ", packet_port
            processInfoResponse(data, packet_ip, packet_port)

        elif request_type == 66:
            # Quit Server (I added this request type so I could stop the server nicely)
            # You will want to remove from a live server to stop malicious people shutting down
            # your server, either that or protect it's use via password or IP restriction.
            print "Received request to terminate server"
            run_server = False

        else:
            print "Unknown request type: ", request_type


    print "Server completed Successfully"        
    g_socket.close()

except:
    
    print "FATAL ERROR OCCURRED"
    g_socket.close()
    raise

Packet sending client. Something to start from.

from socket import *
import struct
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)

UDPSock = socket (AF_INET, SOCK_DGRAM)

data = struct.pack("!c",chr(66))
UDPSock.sendto(data,addr)
UDPSock.close()

thank U for the master server, but can I ask U to show me any example of how to use the other request_type? what pack have I to send?

@drwr i’m sorry, i’m not good to explain