Beispiel #1
0
    def conn_cb(self, wid=None):
        """Join an existing game."""

        # Get IP
        host = fl_input('Enter host IP:', 'localhost').strip() or 'localhost'

        try:
            self.connection = network.Client(self, host=host)
        except ConnectionRefusedError:  # Works on windows, might be different on other platforms
            m = 'ERROR CONNECTING:\nEnsure other player has clicked host game and check IP + ports.'
            fl_alert(m)
            return 0

        # Deactivate options
        self.host_but.deactivate()
        self.menubar.find_item('Game/Host Game').deactivate()
        self.conn_but.deactivate()
        self.menubar.find_item('Game/Join Game').deactivate()

        self.status_box.label(
            'Connected. Place your boats in the left grid (right click to rotate).'
        )

        # Send username and start placing boats
        self.connection.send_data(getuser())
        self.start_placing()
Beispiel #2
0
def main():
    # get CLI arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-a", "--address", help="address of server")
    ap.add_argument("-p", "--port", type=int, help="port of server")
    ap.add_argument("-c",
                    "--channel",
                    help="channels to be monitored, divided by /")
    ap.add_argument("-d",
                    "--delay",
                    type=float,
                    default=0.01,
                    help="refresh delay")
    args = vars(ap.parse_args())

    # initialize client
    client = network.Client(args["address"], args["port"])
    # get channels list
    channel_list = args["channel"].split("/")
    while True:
        for c in channel_list:
            # send channel name to server and show received frames
            cv2.imshow(c, decode_bytes(client.get_data(c)))
        cv2.waitKey(1)
        time.sleep(args["delay"])
Beispiel #3
0
def startClient():
    client = network.Client()
    stat = client.connect()
    if stat == False:
        print("hoo no, server down")
        return None
    time.sleep(1)
    client.send("hallu server !")
Beispiel #4
0
    def setup_sync(self):
        """
        Initialises variables and network objects needed to sync players.
        """
        if SYNC_IS_SERVER:
            self.server = network.Server('', port=10000)

        if SYNC_CLIENT_TO:
            self.client = network.Client(SYNC_CLIENT_TO, port=10000)
Beispiel #5
0
def start_client(address=None, port=None):
    utils.log("Starting...")

    # initialize game
    env.Game.init()
    # initialize resources
    res.Resources.init()

    # start the client connection
    if address is None and port is None:
        env.Game.network_object = network.Client()
    elif address is None:
        env.Game.network_object = network.Client(port=port)
    elif port is None:
        env.Game.network_object = network.Client(address=address)
    else:
        env.Game.network_object = network.Client(address=address, port=port)

    networking_thread = threading.Thread(target=env.Game.network_object.start)
    networking_thread.start()

    utils.log("Ready!")
    while not env.Game.stopped:
        # collect events into list
        events = pygame.event.get()

        # update game states with event list
        env.Game.States.get_active().update(events)

        # resolve user input and send to server
        input_pkg = players.PlayerInputPackage()
        input_pkg.populate_inputs(events)
        env.Game.network_object.send(input_pkg)

        # clear the screen
        env.Game.screen.fill((0, 0, 0))

        # render stuff
        env.Game.States.get_active().render()

        # show n tell
        pygame.display.update()
Beispiel #6
0
def connect(self=False):
    if not self:
        reset_chat()

    client = root.client = network.Client(
        '127.0.0.1' if self else root.address.get(), PORT)

    def on_connect():
        client.perform_login(root.login.get())
        enable_chat()

    client.handle_connect = on_connect
Beispiel #7
0
    def run(self):
        """Start communication with master, movement- and button handler.

        Elev objects are used as a mirror of the real clients on the master
        side, so to initiate connection with the server, move the elevator,
        etc this must be called.
        """
        self.alive = True
        self.client = network.Client(self.master_addr, 10001, self)
        self.ip = network.get_ip()
        self.backup_ip = ''
        self.backup = None
        self.client.send_msg('request_backup_ip', None, self.ip)
        self.worker = network.Msg_receiver(self.client, self.client.connection)
        self.worker.setDaemon(True)
        self.worker.start()
        self.elev = cdll.LoadLibrary("../driver/driver.so")
        self.elev.elev_init(self.mode)
        self.movement = Thread(target=self.movement_handler)
        self.buttons = Thread(target=self.button_handler)
        self.movement.setDaemon(True)
        self.buttons.setDaemon(True)
        self.movement.start()
        self.buttons.start()
Beispiel #8
0
from scenes.change_scene import ChangeScene
from scenes.game_over_scene import GameOverScene
from scenes.history_scene import HistoryScene
from scenes.login_scene import LoginScene
from scenes.menu_scene import MenuScene
from scenes.multi_game_scene import MultiGameScene
from scenes.server_scene import ServerScene
from scenes.setting_scene import SettingScene
from scenes.single_game_scene import SingleGameScene
from scenes.single_or_multi_scene import SingleOrMultiScene
from scenes.stats_scene import StatsScene
from scenes.waiting_scene import WaitingScene

from settings import SCR_HEIGHT, SCR_WIDTH

client = network.Client()
DISCONNECT_MSG = "!DISCONNECT"


def switch_scene():
    if change == "menu":
        return MenuScene(game_window)
    if change == "waiting_scene":
        return WaitingScene(game_window)
    if change == "game":
        return MultiGameScene(game_window)
    if change == "login":
        return LoginScene(game_window)
    if change == "account":
        return AccountScene(game_window)
    if change == "stats":
Beispiel #9
0
 def __init__(self, color, ip):
     Human.__init__(self, color)
     self.client = network.Client(ip)
     self.type = 'Human(Server)'
Beispiel #10
0
 def setUp(self):
     self.host = network.Host('', PORT)
     self.client = network.Client('127.0.0.1', PORT)
Beispiel #11
0
 def setUp(self):
     self.host = network.Host('', PORT)
     self.client1 = network.Client('127.0.0.1', PORT)
     self.client2 = network.Client('127.0.0.1', PORT)
     asyncore_loop()
Beispiel #12
0
 def __init__(self):
     self.connection = network.Client(settings.host, settings.port)
     self.callbacks = {}
Beispiel #13
0
 def recv(self):
     if self.s is None:
         self.s = network.Client()
     return self.s.recv()
Beispiel #14
0
 def send(self, msg):
     if self.s is None:
         self.s = network.Client()
     self.s.send(msg)
Beispiel #15
0
def user(msg):
    user1 = network.Client()
    user1.send(msg)
    time.sleep(5)
    print(user1.dataReceived)
    user1.close()