static void reciver() { if (sk != null) { byte[] data = new byte[256]; StringBuilder builder = new StringBuilder(); int bytes = 0; do { data = new byte[sk.Available]; bytes = sk.Receive(data, data.Length, 0); builder.Append(Encoding.UTF8.GetString(data, 0, bytes)); }while (sk.Available > 0); new recive().ini(builder.ToString()); String b = builder.ToString(); if (old_m.IndexOf("auth") != -1) { auth a = JsonUtility.FromJson <auth>(b); cam.render_me(a); } if (old_m.IndexOf("setPosition") != -1) { user_info [] a = JsonUtility.FromJson <user_info []>(b); for (int w = 0; w < a.Length; w++) { cam.render_or(a[w]); } } if (b.IndexOf("sendMessage") != -1) { mess a = JsonUtility.FromJson <mess>(b); if (a.value.status == 1) { GameObject g = finBbyId(a.id); if (g != null) { g.GetComponent <usr>().sendMess(a.value.text); } } if (a.value.status == 2 || a.value.status == 3) { GameObject g = finBbyId(a.id); if (g != null) { g.GetComponent <usr>().sendhi(); } } } } else { reciver(); } }
void wsSendCommandExecute(mess sendmes) { if (!ws.is_connected) { ws.initWebSocketClient("ws://127.0.0.1:8080/telephon"); } //Здесь передаем при необходимости данные в parameters в зависимости от контента. if (fields != null) { sendmes.parameters = ReturnData(); } ws.sendMessage(sendmes); }
static public IList <ButtonForm> ButtonsFill(XElement parameters, DelegateCommand <mess> com1) { IList <ButtonForm> Buttons4 = new List <ButtonForm>(); foreach (XElement stroca in parameters.Elements("buttonstop")) { mess sendmess = new mess { action = "getform", content = "MainForm", parameters = new[] { "mainform", stroca.Element("parameters").Value }, }; Buttons4.Add(new ButtonForm { Name = stroca.Element("title").Value, Image = stroca.Element("image").Value, com = com1, Parameters = sendmess }); } return(Buttons4); }
public VM_MainWindow() { ws = new WebsocketClient(); ws.Anounesment += Show_String; // Добавляем ссылку на метод в событие. //ws.Announce("Вызов обработчика события успешен"); // Вызываем событие через метод Announce. ws.initWebSocketClient("ws://127.0.0.1:8080/telephon"); wsSendCommand = new DelegateCommand <mess>(wsSendCommandExecute, wsSendCommandCanExecute); Title = "Телефоны"; mess sendmess = new mess { action = "getform", content = "login", parameters = new[] { "", "" }, }; ButtonsDown = new List <ButtonForm>(); ButtonsDown.Add(new ButtonForm { Name = "Подключить", com = wsSendCommand, Parameters = sendmess }); }
IEnumerator listener() { string msg; while (contli) { msg = w.RecvString(); if (msg != null) { //Debug.Log("raw: " + msg); mess msgo = JsonUtility.FromJson <mess>(msg); switch (msgo.msgtype) { case "new connection": newCon nc = JsonUtility.FromJson <newCon>(msgo.content); SocketNetworkManager.id = nc.yourid; newPly n = new newPly(); n.theirid = id; newplayers[id] = n; break; case "new player": newPly np = JsonUtility.FromJson <newPly>(msgo.content); newplayers[np.theirid] = np; numberofplayers++; if (NewPlayerHandle != null) { StartCoroutine(NewPlayerHandle(np)); } break; case "create lobby": creLobby crel = JsonUtility.FromJson <creLobby>(msgo.content); if (CreateLobbyHandle != null) { StartCoroutine(CreateLobbyHandle(crel.lobbyid, crel.playernum)); } break; case "join lobby": joinLobby jnl = JsonUtility.FromJson <joinLobby>(msgo.content); if (JoinLobbyHandle != null) { StartCoroutine(JoinLobbyHandle(jnl.lobbyid, jnl.playernum, jnl.ret)); } break; case "select class": selClass scl = JsonUtility.FromJson <selClass>(msgo.content); if (SelectClassHandle != null) { StartCoroutine(SelectClassHandle(scl.ret, scl.plclass)); } break; case "update class": updClass ucl = JsonUtility.FromJson <updClass>(msgo.content); if (UpdateClassHandle != null) { StartCoroutine(UpdateClassHandle(ucl.player, ucl.plclass)); } break; case "get lobbies": lobbyList ll = JsonUtility.FromJson <lobbyList>(msgo.content); if (GetLobbiesHandle != null) { StartCoroutine(GetLobbiesHandle(ll.lobbiesInfo)); } break; case "general message": genMess gms = JsonUtility.FromJson <genMess>(msgo.content); switch (gms.ct) { case "playerposition": // player position playerPos pp = JsonUtility.FromJson <playerPos>(gms.content); if (UpdateOtherPlayerPos != null) { UpdateOtherPlayerPos(gms.sender, pp.x, pp.y, pp.rx, pp.ry); } break; case "startgame": // start game if (StartGameHandle != null) { StartCoroutine(StartGameHandle()); } break; case "takedamage": // (from boss) opTakeDam otd = JsonUtility.FromJson <opTakeDam>(gms.content); if (TakeDamageHandle != null) { TakeDamageHandle(gms.sender, otd.dmg); } break; case "dealdamage": // (to boss) opDealDam odd = JsonUtility.FromJson <opDealDam>(gms.content); if (DealDamageHandle != null) { DealDamageHandle(gms.sender, odd.dmg, new Vector2(odd.dirx, odd.diry)); } break; case "bossposition": // boss position bossPos bp = JsonUtility.FromJson <bossPos>(gms.content); if (UpdateBossPositionHandle != null) { StartCoroutine(UpdateBossPositionHandle(bp.x, bp.y, bp.rx, bp.ry)); } break; case "playeranimation": // player animation playerAnim pa = JsonUtility.FromJson <playerAnim>(gms.content); if (PlayerAnimHandle != null) { PlayerAnimHandle(gms.sender, pa.name); } break; case "bossanimation": // boss animation bossAnim ba = JsonUtility.FromJson <bossAnim>(gms.content); if (BossAnimHandle != null) { StartCoroutine(BossAnimHandle(ba.name)); } break; case "spawnprojectile": // spawn projectile spawnProj sp = JsonUtility.FromJson <spawnProj>(gms.content); if (SpawnProjHandle != null) { SpawnProjHandle(gms.sender, sp.name, new Vector2(sp.x, sp.y), new Vector2(sp.dx, sp.dy), new Quaternion(sp.rx, sp.ry, sp.rz, sp.rw)); } break; default: Debug.Log("unknown general message type"); Debug.Log(gms.ct); break; } break; default: Debug.Log("unknown message type"); break; } msg = null; } yield return(new WaitForEndOfFrame()); } }
bool wsSendCommandCanExecute(mess sendmes) { return(true); }