//abuse public void OnJoinGame(NetworkConnection conn, JoinMessage Join) { NetPlayer NP = Instantiate(playerPrefab).GetComponent <NetPlayer>(); NetworkServer.AddPlayerForConnection(conn, NP.gameObject); PlayerBrain PB = Instantiate(GamePlayer); NetworkServer.Spawn(PB.gameObject, conn); for (int i = 0; i < 25; i++) { ItemBox IB = Instantiate(ItemBox); NetworkServer.Spawn(IB.gameObject); IB.Randomize(); } for (int i = 0; i < 5; i++) { PlatBrain PlB = Instantiate(PlatGuy); PlB.transform.position = new Vector3(300, 300, 0) * Random.insideUnitCircle; NetworkServer.Spawn(PlB.gameObject); PlB.Die(); } //Players.Add(NP.netId, NP); //PlayerBrains.Add(NP.netId, PB); JoinedMessage joined = new JoinedMessage(); //Debug.Log(NP.netId+"|"+PB.netId); joined.id = NP.netId; joined.Player = PB.netId; NetworkServer.SendToAll(joined); }
static async Task Joined(SocketGuildUser user) { var g = user.Guild; var isx = (await g.GetInvitesAsync()).ToList(); string code = "nocode"; foreach (var i in isx) { var laststate = await InviteCounterSql.GetGuild(g, i); if (laststate < i.Uses) { code = i.Code; if (laststate < 1) { await InviteCounterSql.AddGuild(g, i); } else { await InviteCounterSql.UpdateGuildName(g, i); } } } //this is where you use the code JoinedMessage jm = await JoinedMessage.CreateFromUser(user, code); await MessageHandler.DoGuildMessage(jm); }
public void OnJoinedGame(NetworkConnection conn, JoinedMessage Join) { //Debug.Log(NetworkIdentity.spawned.Count+"C"); //Debug.Log(Join.id+"|"+Join.Player); //Debug.Log(NetworkIdentity.spawned.TryGetValue(Join.Player, out) +"PBI"); NetworkIdentity NPI = NetworkIdentity.spawned[Join.id]; NetworkIdentity PBI = NetworkIdentity.spawned[Join.Player]; //Debug.Log(NetworkIdentity.spawned.TryGetValue(Join.id, out NetworkIdentity NPI) + "NPI"); NetPlayer NP = NPI.GetComponent <NetPlayer>(); PlayerBrain PB = PBI.GetComponent <PlayerBrain>(); Players.Add(Join.id, NP); PlayerBrains.Add(Join.id, PB); Debug.Log("Completed"); }
IEnumerator WebSocketCoroutine() { webSocket = new WebSocket(new Uri(serverAddress)); yield return(StartCoroutine(webSocket.Connect())); while (true) { string reply = webSocket.RecvString(); if (reply != null) { Debug.Log("Received msg:" + reply); Message msg = fastJSON.JSON.ToObject <Message>(reply); switch (msg.type) { case "logged_in": LoggedInMessage lm = fastJSON.JSON.ToObject <LoggedInMessage>(reply); Debug.Log("Logged in!, characters: " + lm.characters); loginScript.AddCharacters(lm.characters); break; case "joined": JoinedMessage jm = fastJSON.JSON.ToObject <JoinedMessage>(reply); playerScript.playerId = jm.id; // todo: camera follow Debug.Log("Joined!, playerId = " + jm.id); loginPanel.SetActive(false); break; case "update": UpdateMessage umsg = (UpdateMessage)fastJSON.JSON.ToObject(reply, typeof(UpdateMessage)); Debug.Log("update type: " + umsg.type); Debug.Log("updates: " + umsg.updates); Debug.Log("List size: " + umsg.updates.Count); foreach (var m in umsg.updates) { Dictionary <string, object> update = (Dictionary <string, object>)m; var type = (string)update["type"]; Debug.Log("update.type = " + type); switch (type) { case "appear": Debug.Log("update.type = " + update["type"]); Debug.Log("update.object_type = " + update["object_type"]); Debug.Log("update.id = " + update["id"]); Debug.Log("update.x = " + update["x"]); Debug.Log("update.y = " + update["y"]); objectManager.InstantiateObject((string)update["object_type"], (string)update["id"], (long)update["x"], (long)update["y"]); break; case "disappear": Debug.Log("Removing object"); objectManager.DestroyObject((string)update["id"]); break; case "change": Debug.Log("update.id = " + update["id"]); Debug.Log("update.field = " + update["field"]); Debug.Log("update.new_value = " + update["new_value"]); objectManager.Change((string)update["id"], (string)update["field"], (string)update["new_value"]); break; case "movement": Debug.Log("update.id = " + update["id"]); Debug.Log("update.x = " + update["x"]); Debug.Log("update.y = " + update["y"]); objectManager.Move((string)update["id"], (long)update["x"], (long)update["y"]); break; } } break; } Debug.Log("Received type: " + msg.type); } if (webSocket.error != null) { Debug.Log(reply); break; } yield return(new WaitForSeconds(0.01f)); } }