protected NwkClientData addClient(int newUid, int newConnId = -1) { NwkClientData data = getClientData(newUid); if (data == null) { data = new NwkClientData(newUid); data.connId = newConnId; clientDatas.Add(data); } //data.setConnected(); return(data); }
void OnClientConnected(NetworkMessage clientConnectionMessage) { log("OnClientConnected ; sending ping pong transaction"); //server prepare message to ask for uid of newly connected client //to send only to new client server will use connectionId stored within origin conn message NwkMessageTransaction transMessage = new NwkMessageTransaction(); transMessage.getIdCard().setupId(0, (int)eNwkMessageType.CONNECTION_PINGPONG); //give message to listener system to plug a callback sendWrapper.sendTransaction(transMessage, clientConnectionMessage.conn.connectionId, delegate(NwkMessageTransaction waybackMessage) { // --- CALLBACK TRANSACTION log("received uid from client : " + waybackMessage.getIdCard().getMessageSender() + " , token ? " + waybackMessage.token); NwkClientData data = addClient(waybackMessage.getIdCard().getMessageSender(), clientConnectionMessage.conn.connectionId); // server ref new client in list data.setConnected(); // mark as connected //broadcast to all NwkMessageFull msg = new NwkMessageFull(); msg.getIdCard().setupId(0, (int)eNwkMessageType.CONNECTION); msg.header.setupHeader(waybackMessage.getIdCard().getMessageSender().ToString()); // msg will contain new client uid //send new client UID to everybody sendWrapper.broadcastServerToAll(msg, 0); // --- }); //log("asking to new client its uid"); //NwkUiView nView = qh.gc<NwkUiView>(); //if (nView != null) nView.onConnection(); }