protected override void NewPlayer(NetIncomingMessage msg) { NetPlayer player = new NetPlayer(0, 0); string name = msg.ReadString(); int uid = msg.ReadInt32(); player.UID = uid; ClientInfo clientInfo = new ClientInfo(); clientInfo.Name = name; clientInfo.X = player.X; clientInfo.Y = player.Y; clientInfo.UID = uid; if (!NetManager.connectedClients.ContainsKey(uid)) { NetManager.connectedClients.Add(clientInfo.UID, clientInfo); EntityManager.AddNetPlayer(player); JapeLog.WriteLine("New Player Added: " + name); } }
protected void NewPlayerResponse(NetIncomingMessage msg) { int ownUid = msg.ReadInt32(); NetManager.RemoteUID = ownUid; bool gameStarted = msg.ReadBoolean(); string levelName = msg.ReadString(); string levelData = msg.ReadString(); int otherClientsCount = msg.ReadInt32(); for (int i = 0; i < otherClientsCount; i++) { string name = msg.ReadString(); int uid = msg.ReadInt32(); NetPlayer player = new NetPlayer(0, 0); ClientInfo clientInfo = new ClientInfo(); clientInfo.Name = name; clientInfo.X = player.X; clientInfo.Y = player.Y; clientInfo.UID = uid; player.UID = uid; if (!NetManager.connectedClients.ContainsKey(uid)) { NetManager.connectedClients.Add(clientInfo.UID, clientInfo); EntityManager.AddNetPlayer(player); JapeLog.WriteLine("New Player Added: " + name); } } if (gameStarted) { DownloadLevel(levelName, levelData); OnChangedLevel(levelName, 0); } JapeLog.WriteLine("Remote ID recieved: " + ownUid); }
private static void KickClient(ClientInfo client) { client.ClientNetConnection.Disconnect("You were kicked by the host"); string reason = "Kicked in the ass"; SendMessageParamsStringsOnly(NetDeliveryMethod.ReliableOrdered, (int)DataType.PlayerDisconnected, client.UID.ToString(), client.Name, reason ); //connectedClients.Remove(client.UID); client.Disconnected = true; }
protected static void AlertOthersNewPlayer(NetConnection excludeConnection, ClientInfo info) { foreach (var dic in NetManager.connectedClients) { var conn = dic.Value.ClientNetConnection; if (conn != excludeConnection) { /*SendMessageParams(NetDeliveryMethod.ReliableOrdered, conn, (int)DataType.NewPlayer, info.Name, info.UID );*/ NetOutgoingMessage oMsg = NetManager.CreateMessage(); oMsg.Write((int)DataType.NewPlayer); oMsg.Write(info.Name); oMsg.Write(info.UID); NetManager.SendMessage(NetDeliveryMethod.ReliableOrdered, oMsg, conn); } } NetOutgoingMessage oMsg2 = NetManager.CreateMessage(); oMsg2.Write((int)DataType.NewPlayerResponse); oMsg2.Write(info.UID); oMsg2.Write(NetManager.GameStarted); oMsg2.Write(Runtime.CurrentLevel.Name); oMsg2.Write(Runtime.CurrentLevel.Data); //GetlevelData oMsg2.Write(NetManager.connectedClients.Count - 1); foreach (var item in NetManager.connectedClients) { if (info.UID == item.Value.UID) continue; oMsg2.Write(item.Value.Name); oMsg2.Write(item.Value.UID); } NetManager.SendMessage(NetDeliveryMethod.ReliableOrdered, oMsg2, excludeConnection); }
protected void NewPlayerResponse(NetIncomingMessage msg) { int ownUid = msg.ReadInt32(); NetManager.RemoteUID = ownUid; int otherClientsCount = msg.ReadInt32(); for (int i = 0; i < otherClientsCount; i++) { string name = msg.ReadString(); int uid = msg.ReadInt32(); ClientInfo clientInfo = new ClientInfo(); clientInfo.Name = name; clientInfo.X = 0; clientInfo.Y = 0; clientInfo.UID = uid; if (!NetManager.connectedClients.ContainsKey(uid)) { NetManager.connectedClients.Add(clientInfo.UID, clientInfo); JapeLog.WriteLine("New Player Added: " + name); } } JapeLog.WriteLine("Remote ID recieved: " + ownUid); }
protected void NewPlayer(NetIncomingMessage msg) { string name = msg.ReadString(); msg.ReadInt32(); int uid = NetManager.CreateNewUID(); ClientInfo clientInfo = new ClientInfo(); clientInfo.Name = name; clientInfo.X = 0; clientInfo.Y = 0; clientInfo.ClientNetConnection = msg.SenderConnection; clientInfo.UID = uid; NetManager.connectedClients.Add(clientInfo.UID, clientInfo); AlertOthersNewPlayer(msg.SenderConnection, clientInfo); JapeLog.WriteLine("New Player Added: " + name); }