Beispiel #1
0
def client_receive_message(mess, sock):
    """Run when the client receives a message."""
    global clplayer, am_client
    print >>riskengine.verbosefile, mess, "client received"
    parts = splitparms(mess)
    if parts[0] == "draw_army" or parts[0] == "draw_territory":
        terr = riskengine.territories[parts[1]]
        terr.armies = int(parts[2])
        terr.player = riskengine.players[parts[3]]
        if parts[0] == "draw_army":
            riskgui.drawarmy(terr)
        else:
            riskgui.drawterritory(terr, int(parts[4]))
    if parts[0] == "set_armies":
        riskgui.set_armies(int(parts[1]))
    if parts[0] == "won_game":
        riskgui.won_game(parts[1])
    if parts[0] == "playersturn":
        riskgui.playersturn(parts[1])
    if parts[0] == "set_status":
        riskgui.set_status(parts[1])
    if parts[0] == "newplayer":
        riskgui.net_newplayer(parts[1])
    if parts[0] == "removeplayer":
        riskgui.removeplayer(parts[1])   
    if parts[0] == "relistplayers":
        riskgui.relistplayers([riskengine.players[p] for p in parts[1:]])
    if parts[0] == "set_phase":
        riskengine.setphase(parts[1])
    if parts[0] == "add_card":
        riskengine.players[parts[3]].cards.append(riskengine.Card(parts[2], parts[1]))
    if parts[0] == "remove_card":
        foundcard = 0
        for n in riskengine.players[parts[3]].cards:
            if n.territory == parts[2]:
                riskengine.players[parts[3]].cards.remove(n)
                foundcard = 1
                break
        if foundcard == 0:
            print >>riskengine.verbosefile, "Couldn't find card"
            print >>riskengine.verbosefile, "players' cards:", riskengine.players[parts[3]].cards
        #riskengine.players[parts[3]].cards.remove(riskengine.card(parts[2], parts[1]))
    if parts[0] == "message":
        riskgui.set_status(parts[2] + " sent message: " + parts[1])
    if parts[0] == "leaving":
        riskgui.show_status_message("The server has left.")
        serv_sock.close()
        am_client = 0
Beispiel #2
0
def client_receive_message(mess, sock):
    """Run when the client receives a message."""
    global clplayer, am_client
    print >>riskengine.verbosefile, mess, "client received"
    parts = splitparms(mess)
    if parts[0] == "draw_army" or parts[0] == "draw_territory":
        terr = riskengine.territories[parts[1]]
        terr.armies = int(parts[2])
        terr.player = riskengine.players[parts[3]]
        if parts[0] == "draw_army":
            riskgui.drawarmy(terr)
        else:
            riskgui.drawterritory(terr, int(parts[4]))
    if parts[0] == "set_armies":
        riskgui.set_armies(int(parts[1]))
    if parts[0] == "won_game":
        riskgui.won_game(parts[1])
    if parts[0] == "playersturn":
        riskgui.playersturn(parts[1])
    if parts[0] == "set_status":
        riskgui.set_status(parts[1])
    if parts[0] == "newplayer":
        riskgui.net_newplayer(parts[1])
    if parts[0] == "removeplayer":
        riskgui.removeplayer(parts[1])
    if parts[0] == "relistplayers":
        riskgui.relistplayers([riskengine.players[p] for p in parts[1:]])
    if parts[0] == "set_phase":
        riskengine.setphase(parts[1])
    if parts[0] == "add_card":
        riskengine.players[parts[3]].cards.append(riskengine.Card(parts[2], parts[1]))
    if parts[0] == "remove_card":
        foundcard = 0
        for n in riskengine.players[parts[3]].cards:
            if n.territory == parts[2]:
                riskengine.players[parts[3]].cards.remove(n)
                foundcard = 1
                break
        if foundcard == 0:
            print >>riskengine.verbosefile, "Couldn't find card"
            print >>riskengine.verbosefile, "players' cards:", riskengine.players[parts[3]].cards
        # riskengine.players[parts[3]].cards.remove(riskengine.card(parts[2], parts[1]))
    if parts[0] == "message":
        riskgui.set_status(parts[2] + " sent message: " + parts[1])
    if parts[0] == "leaving":
        riskgui.show_status_message("The server has left.")
        serv_sock.close()
        am_client = 0
Beispiel #3
0
def server_receive_message(mess, sock):
    """Run when the server receives a message"""
    print >>riskengine.verbosefile, mess, "server received"
    parts = splitparms(mess)
    if parts[0] == "newplayer":
        riskgui.net_newplayer(parts[1])
        riskengine.players[parts[1]].connection = sock
        for sck in sockets:
            if sck != sock:
                sendparts(sck, "newplayer", parts[1])
    if parts[0] == "handle_selection":
        if hasattr(riskengine.currentplayer, "connection") and riskengine.currentplayer.connection == sock:
            riskengine.handleselection(riskengine.territories[parts[1]], int(parts[2]))
    if parts[0] == "start_fortifying":
        riskengine.startfortifying()
    if parts[0] == "next_turn":
        riskengine.nextturn()
    if parts[0] == "turnincards":
        if hasattr(riskengine.currentplayer, "connection") and riskengine.currentplayer.connection == sock:
            cd = []
            for c in riskengine.currentplayer.cards:
                if c.territory in parts[1:]:
                    cd.append(c)
            riskengine.turnincards(riskengine.currentplayer, cd)
    if parts[0] == "message":
        pla = sockettoplayer(sock)
        if pla:
           plname = pla.name
        else:
           plname = "Someone"
        riskgui.set_status(plname + " sent message: " + parts[1])
    if parts[0] == "leaving":
        sockets.remove(sock)
        sock.close()
        pla = sockettoplayer(sock)
        if pla:
           plname = pla.name
        else:
           plname = "Someone"
        riskgui.set_status(plname + " has left")
            
Beispiel #4
0
def server_receive_message(mess, sock):
    """Run when the server receives a message"""
    print >>riskengine.verbosefile, mess, "server received"
    parts = splitparms(mess)
    if parts[0] == "newplayer":
        riskgui.net_newplayer(parts[1])
        riskengine.players[parts[1]].connection = sock
        for sck in sockets:
            if sck != sock:
                sendparts(sck, "newplayer", parts[1])
    if parts[0] == "handle_selection":
        if hasattr(riskengine.currentplayer, "connection") and riskengine.currentplayer.connection == sock:
            riskengine.handleselection(riskengine.territories[parts[1]], int(parts[2]))
    if parts[0] == "start_fortifying":
        riskengine.startfortifying()
    if parts[0] == "next_turn":
        riskengine.nextturn()
    if parts[0] == "turnincards":
        if hasattr(riskengine.currentplayer, "connection") and riskengine.currentplayer.connection == sock:
            cd = []
            for c in riskengine.currentplayer.cards:
                if c.territory in parts[1:]:
                    cd.append(c)
            riskengine.turnincards(riskengine.currentplayer, cd)
    if parts[0] == "message":
        pla = sockettoplayer(sock)
        if pla:
            plname = pla.name
        else:
            plname = "Someone"
        riskgui.set_status(plname + " sent message: " + parts[1])
    if parts[0] == "leaving":
        sockets.remove(sock)
        sock.close()
        pla = sockettoplayer(sock)
        if pla:
            plname = pla.name
        else:
            plname = "Someone"
        riskgui.set_status(plname + " has left")