1

Im quite new to ursina engine and i tried to do a multiplayer game. the point is that multiple clients can connect on a server and play together. But if i play with more than two clients at once or if the client disconnects and reconnect too much, i get this error :

Assertion failed: !is_empty() at line 961 of panda/src/pgraph/nodePath.cxx

here is my code,

Server

from ursinanetworking import *
from ursina import *

server = UrsinaNetworkingServer('192.168.1.34',22625)

App = Ursina()

x,y = 0,0
clientxandy = []
clientplayers = []
nb_clients = 0
ground = Entity(model='ground.obj', scale=(10,1,10), color=color.white, texture='white_cube',texture_scale=(10,10)) 
#soil.rotation_z = 90
clients_pos = []
ec = EditorCamera(rotation_smoothing=10, enabled=1, rotation=(30,30,0))
ID = 0
last_id = 0
rotation_info = Text(position=window.top_left)
client_names = []

def update():
    rotation_info.text = str(int(ec.rotation_y)) + '\n' + str(int(ec.rotation_x))

@server.event
def onClientConnected(Client):
    global nb_clients,ID,last_id
    print(f'{Client} joined the game!')
    Client.send_message("ID", last_id)
    clientxandy.append((0,0))
    clientplayers.append(Entity(model="person.obj", position=(0,5,0), color=color.red,collider='sphere'))
    nb_clients += 1
    last_id += 1
    clients_pos.append((0,0,0))
    client_names.append(str(Client))

'''
@server.event
def onClientDisconnected(Client):
    global nb_clients
    ID = str(Client)
    ID = ID.replace("Client ", "")
    ID = int(ID)
    destroy(clientplayers[ID])
    clients_pos.pop(clientplayers[ID])
    print("Client"+ str(ID) + "left the game" )
    
    nb_clients -=1
''' 

@server.event
def clientdisconnect(Client, Content):
    global nb_clients,last_id
    ID = str(Client)
    ID = ID.replace("Client ", "")
    ID = int(ID)
    del clients_pos[0]
    destroy(clientplayers[ID])
    print("Client"+ str(ID) + "left the game" )
    
    nb_clients -=1
    last_id-=1
    
@server.event
def xycoords(Client, Content):
    global x,y,z, last_id,clients_pos
    #print(f"{Client} says : {Content}")
    x = Content[0]
    y = Content[1]
    z = Content[2]
    clientname = str(Client)
    clientid = str(Client)
    clientid = clientid.replace("Client " ,"")
    clientplayers[int(Content[3])].position = (x,y,z)
    clients_pos[Content[3]] = (x,y,z)
    #print(Content[3])
    #print(clients_pos)
    Client.send_message("xandyotherplayers",clients_pos)

def update():
    global nb_clients,last_id
    #print(last_id)
    #test = Entity(model="person.obj", position=(0,0), color=color.red)
    server.process_net_events()

App.run()

Client

from ursinanetworking import *
from ursina.prefabs.first_person_controller import FirstPersonController

client = UrsinaNetworkingClient('192.168.1.34', 22625)
counter = 0

App = Ursina()

Id = 0
x,y = 0,0
pos_list = []
playersingame = 0
otherplayers = []
lastplayersingame = 0
ground = Entity(model = "ground.obj", scale = (10,1,10), color = color.white, texture = "white_cube", texture_scale=(10,10), collider="mesh")
player = FirstPersonController(origin_x=0,origin_z=0,origin_y=5, mouse_sensivity=Vec2(40,40),jump_height=2,collider = 'cube')
#playertest = Entity(model = "person.obj",position=(0,0), color=color.white)

@client.event
def onConnectionEtablished():
    print('Client successfully connected!')

@client.event
def onConnectionError(Reason):
    print('Client failed to connect, the reason is : ' + Reason)

@client.event
def ID(Content):
    global Id
    print(Content)
    Id = int(Content)

@client.event
def xandyotherplayers(Content):
    global Id, playersingame,lastplayersingame,pos_list,other_players,counter
    pos_list = Content.pop(Id)
    #print(len(pos_list))
    playersingame = len(Content)
    print(Content)
    if playersingame != lastplayersingame:
        if playersingame < lastplayersingame:
            destroy(otherplayers[0])

        for i in range(playersingame-lastplayersingame):

            otherplayer = Entity(model = "person.obj", color = color.white, texture = "white_cube", texture_scale=(10,2),collider='person.obj')
            otherplayers.append(otherplayer)
        lastplayersingame = playersingame
    for player in otherplayers:
        print(otherplayers)
        player.position = (Content[counter])
        counter +=1
    counter = 0

def update():

    global x,y,Id,player
    client.send_message("xycoords",(player.x,player.y,player.z,Id))

    client.process_net_events()
    if held_keys["a"]:
        x-=0.1
    if held_keys["d"]:
        x+=0.1
    if held_keys["w"]:
        y+=0.1
    if held_keys["s"]:
        y-=0.1
    if held_keys["q"]:
        client.send_message("clientdisconnect","byee! :D")
        quit()
    if player.y <= -20:
        player.y = 5
        player.x =0
        player.z=0

App.run()

What did i do wrong?

user11717481
  • 1
  • 9
  • 15
  • 25
  • always put FULL error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information in the full error/traceback. – furas Oct 16 '22 at 21:46
  • when client disconnect you may have to remove it with all `clientxandy`, `clientplayers`, `client_names`. It would be simpler if you would keep it as single list with dictionares: `clients = [{"name": ..., "x": ... , "y": ..., ...}, {"name": ..., "x": ... , "y": ..., ...}, ...]` – furas Oct 16 '22 at 21:49
  • The error seems to be caused by the server interface, for now, I just deleted the client display but the server display should work if i search a little more, I cant try right now, but i will try it soon. – Proplayer2020 Oct 17 '22 at 16:43
  • edit : server side work now but the client throw assertion error when i try to disconnect and reconnect another client(when the other client respawn the error is back). – Proplayer2020 Oct 17 '22 at 18:51

1 Answers1

0

Finally i made it work. I deleted the server display and i put a try except because of "list assignment out of range". new code:

server

from ursinanetworking import *
from ursina import *


server = UrsinaNetworkingServer('192.168.1.34',22625)

App = Ursina()
x,y,z = 0,0,0

clientplayers = []
nb_clients = 0
ground = Entity(model='ground.obj', scale=(10,1,10), color=color.white, texture='white_cube',texture_scale=(10,10)) 
#soil.rotation_z = 90
clients_pos = []
ec = EditorCamera(rotation_smoothing=10, enabled=1, rotation=(30,30,0))
ID = 0
last_id = 0
rotation_info = Text(position=window.top_left)

def update():
    rotation_info.text = str(int(ec.rotation_y)) + '\n' + str(int(ec.rotation_x))

@server.event
def onClientConnected(Client):
    global nb_clients,ID,last_id
    print(f'{Client} joined the game!')
    Client.send_message("ID", last_id)
    
    clientplayers.append(Entity(model="person.obj", position=(0,5,0), color=color.red,collider='sphere'))
    nb_clients += 1
    last_id += 1
    clients_pos.append((0,0,0))
    

@server.event
def clientdisconnect(Client, Content):
    global nb_clients,last_id
    ID = str(Client)
    ID = ID.replace("Client ", "")
    ID = int(ID)
    del clients_pos[0]
    destroy(clientplayers[ID])
    print("Client"+ str(ID) + "left the game" )
    
    nb_clients -=1
    last_id-=1
    
@server.event
def xycoords(Client, Content):
    global x,y,z, last_id,clients_pos,clientplayers
    #print(f"{Client} says : {Content}")
    x = Content[0]
    y = Content[1]
    z = Content[2]
    clientname = str(Client)
    clientid = str(Client)
    clientid = clientid.replace("Client " ,"")
    #clientplayers[int(clientid)].position = (x,y,z)
    try:
        clients_pos[int(clientid)] = (x,y,z)
    except:
        clients_pos[0] = (x,y,z)
    
    
    #print(Content[3])
    #print(clients_pos)
    Client.send_message("xandyotherplayers",clients_pos)

client

from ursinanetworking import *
from ursina.prefabs.first_person_controller import FirstPersonController

client = UrsinaNetworkingClient('192.168.1.34', 22625)
counter = 0
App = Ursina()
Id = 0
x,y = 0,0
pos_list = []
playersingame = 0
otherplayers = []
lastplayersingame = 0
ground = Entity(model = "ground.obj", scale = (10,1,10), color = color.white, texture = "white_cube", texture_scale=(10,10), collider="mesh")
player = FirstPersonController(origin_x=0,origin_z=0,origin_y=5, mouse_sensivity=Vec2(40,40),jump_height=2,collider = 'cube')
#playertest = Entity(model = "person.obj",position=(0,0), color=color.white)

@client.event
def onConnectionEtablished():
    print('Client successfully connected!')


@client.event
def onConnectionError(Reason):
    print('Client failed to connect, the reason is : '+Reason)
@client.event
def ID(Content):
    global Id
    print(Content)
    Id = int(Content)
    print(Id)
@client.event
def xandyotherplayers(Content):
    global Id, playersingame,lastplayersingame,pos_list,other_players,counter
    pos_list = Content.pop(Id)
    #print(len(pos_list))
    playersingame = len(Content)
    #print(Content)
    if playersingame != lastplayersingame:
        if playersingame < lastplayersingame:
            destroy(otherplayers[0])
            
            del otherplayers[0]
            print(otherplayers)

        for i in range(playersingame-lastplayersingame):

            otherplayer = Entity(model = "person.obj", color = color.white, texture = "white_cube", texture_scale=(10,2),collider='person.obj')
            otherplayers.append(otherplayer)
        lastplayersingame = playersingame
    for player in otherplayers:
        #print(otherplayers)
        
        player.position = (Content[counter])
        counter +=1
    counter = 0

def update():

    global x,y,Id,player
    client.send_message("xycoords",(player.x,player.y,player.z,Id))

    client.process_net_events()
    if held_keys["a"]:
        x-=0.1
    if held_keys["d"]:
        x+=0.1
    if held_keys["w"]:
        y+=0.1
    if held_keys["s"]:
        y-=0.1
    if held_keys["q"]:
        client.send_message("clientdisconnect","byee! :D")
        quit()
    if player.y <= -20:
        player.y = 5
        player.x =0
        player.z=0
    


App.run()