Exemple #1
0
def snapshot():
    while True:
        time.sleep(1. / config['sv_updaterate'])

        global snapshots_history
        with lock:
            # keep only the most recent snapshots
            snapshots_history = {
                seq: world
                for seq, world in snapshots_history.items()
                if seq >= last_snapshot_ack
            }

            # create the snapshot using the last acknowledged state
            snapshot = bytes(
                w.World.diff(snapshots_history[last_snapshot_ack], world))

        # build and transmit the message
        sv_message = m.ServerMessage(op=m.ServerMessage.SNAPSHOT,
                                     data=snapshot)
        message_seq = netchan.transmit(
            m.Message(reliable=False, data=sv_message.SerializeToString()))

        logger.info(f'snapshot id={message_seq} using id={last_snapshot_ack}')

        with lock:
            # keep the snapshot in the history
            snapshots_history[message_seq] = copy.deepcopy(world)
Exemple #2
0
def ack():
    while True:
        time.sleep(1. / config['cl_cmdrate'])

        cl_message = m.ClientMessage(data=b'ack')
        netchan.transmit(
            m.Message(reliable=False, data=cl_message.SerializeToString()))
Exemple #3
0
def noise():
    while True:
        time.sleep(0.20)

        sv_message = m.ServerMessage(op=m.ServerMessage.NOOP, data=b'noop')
        netchan.transmit(
            m.Message(reliable=False, data=sv_message.SerializeToString()))
Exemple #4
0
 def GetGroupChat(self, request, context):
     return messages_pb2.GroupChat(
         group_chat_id=51,
         title="Test title",
         member_user_ids=[2, 3, 4],
         admin_user_ids=[10042434, 293, 1],
         only_admins_invite=True,
         is_dm=False,
         created=Timestamp_from_datetime(now()),
         unseen_message_count=15,
         last_seen_message_id=8839123,
         latest_message=messages_pb2.Message(
             message_id=119,
             author_user_id=309,
             time=Timestamp_from_datetime(now()),
             text=messages_pb2.MessageContentText(
                 text="this is a pretend message"),
         ),
     )
Exemple #5
0
 def on_key_press(symbol, modifiers):
     cl_message = None
     if symbol == pyglet.window.key.D:
         cl_message = m.ClientMessage(commands=[
             m.ClientMessage.Command(
                 id=m.ClientMessage.Command.SIM_DELETE_RANDOM_ENTITY)
         ])
     elif symbol == pyglet.window.key.P:
         world.toggle_pause()
         cl_message = m.ClientMessage(commands=[
             m.ClientMessage.Command(
                 id=m.ClientMessage.Command.SIM_TOGGLE_PAUSE)
         ])
     elif symbol == pyglet.window.key.S:
         cl_message = m.ClientMessage(commands=[
             m.ClientMessage.Command(
                 id=m.ClientMessage.Command.SIM_SPAWN_RANDOM_ENTITY)
         ])
     if cl_message:
         netchan.transmit(
             m.Message(reliable=True, data=cl_message.SerializeToString()))
Exemple #6
0
    def noop(netchan):
        while True:
            time.sleep(0.30)

            netchan.transmit(m.Message(reliable=False, data=b'noop'))
Exemple #7
0
        )
        if message.reliable:
            assert message.data == next(sv_data_to_recv)

    def cl_process_callback(message):
        logger.info(
            f'cl: process_callback msgseq={message.seq} msgack={message.ack} reliable={message.reliable} data={message.data}'
        )
        if message.reliable:
            assert message.data == next(cl_data_to_recv)

    recv_rate = send_rate = 10
    sv_netchan = NetChannel(sv_sock, cl_addr, sv_process_callback, recv_rate, send_rate)
    cl_netchan = NetChannel(cl_sock, sv_addr, cl_process_callback, recv_rate, send_rate)

    def noop(netchan):
        while True:
            time.sleep(0.30)

            netchan.transmit(m.Message(reliable=False, data=b'noop'))

    threading.Thread(target=noop, daemon=True, args=(sv_netchan, )).start()
    threading.Thread(target=noop, daemon=True, args=(cl_netchan, )).start()

    for i in range(num_reliable_messages_to_send):
        time.sleep(0.15)

        sv_netchan.transmit(m.Message(reliable=True, data=sv_data_to_send[i]))
        cl_netchan.transmit(m.Message(reliable=True, data=cl_data_to_send[i]))
    time.sleep(3.00)
Exemple #8
0
#!/usr/bin/env python3
import sys
sys.path.insert(0, './proto_py')

import messages_pb2
import socket

mes = messages_pb2.Message()

HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
PORT = 65432  # Port to listen on (non-privileged ports are > 1023)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            mes.ParseFromString(data)
            mes.name = 'changed on a server'
            mes.id = 24234
            print('end')
            conn.sendall(mes.SerializeToString())