Advertisement
Guest User

adsasdasd

a guest
Jan 22nd, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5.  
  6. using EasyJSON;
  7.  
  8.  
  9. public class EqemuConnect : MonoBehaviour {
  10. public GameObject EqemuConnectObject;
  11. public GameObject elf;
  12.  
  13. // Use this for initialization
  14. IEnumerator Start () {
  15. WebSocket w = new WebSocket(new Uri("ws://IP:PORT"));
  16. yield return StartCoroutine(w.Connect());
  17.  
  18.  
  19. Auth auth1 = new Auth();
  20. auth1.id = "token_auth_id";
  21. auth1.method = "WebInterface.Authorize";
  22. auth1.@params = new string[1] {"TOKEN"};
  23.  
  24. // EASYJSON Serialize the entity into a JSON string
  25. string authoutput = Serializer.Serialize(auth1);
  26. // send auth to server
  27. w.SendString(authoutput);
  28.  
  29.  
  30. GetInitialEntitiyPositions GetInitialEntitiyPositions1 = new GetInitialEntitiyPositions();
  31. GetInitialEntitiyPositions1.id = "get_initial_entity_positions";
  32. GetInitialEntitiyPositions1.method = "Zone.GetInitialEntityPositions";
  33. GetInitialEntitiyPositions1.@params = new string[2] {EqemuConnectObject.tag,"0"};
  34.  
  35. // EASYJSON Serialize the entity into a JSON string
  36. string output2 = Serializer.Serialize(GetInitialEntitiyPositions1);
  37. // Request Entity Positions from server
  38. w.SendString(output2);
  39.  
  40. int i=0;
  41. while (true)
  42. {
  43.  
  44. string reply = w.RecvString();
  45.  
  46. if (reply != null)
  47. {
  48. // Print responses to console
  49. // Debug.Log ("Received: "+reply+i++);
  50. Debug.Log("i =" + i++);
  51.  
  52. //deserialize
  53. //eqemu json start
  54. if (i > 1)
  55. {
  56. string JsonArray = ("[" + reply + "]");
  57. MyClass[] jsonObject = Serializer.Deserialize<MyClass[]>(JsonArray);
  58.  
  59. float fx = Single.Parse(Result.x);
  60. float fy = Single.Parse(Result.y);
  61. float fz = Single.Parse(Result.z);
  62. // Debug.Log("name:" + Result.name);
  63. // Debug.Log("X:" + Result.x);
  64. // Debug.Log("y:" + Result.y);
  65. // Debug.Log("z:" + Result.z);
  66.  
  67.  
  68.  
  69.  
  70. if (Result.type == "NPC")
  71. {
  72. Instantiate(elf, new Vector3(-fx, fz, fy), Quaternion.identity);
  73. }
  74. }
  75.  
  76.  
  77.  
  78.  
  79. }
  80. if (w.Error != null)
  81. {
  82. Debug.LogError ("Error: "+w.Error);
  83. break;
  84. }
  85. yield return 0;
  86. }
  87. w.Close();
  88. }
  89.  
  90. public class Auth {
  91. public string id;
  92. public string method;
  93. public string[] @params;
  94.  
  95.  
  96. }
  97.  
  98. public class GetInitialEntitiyPositions {
  99. public string id;
  100. public string method;
  101. public string[] @params;
  102.  
  103. }
  104.  
  105.  
  106. public class Result {
  107. public static string aggro_range { get; set; }
  108. public static string class_id { get; set; }
  109. public static string ent_id { get; set; }
  110. public static string h { get; set; }
  111. public static string name { get; set; }
  112. public static string race_id { get; set; }
  113. public static string type { get; set; }
  114. public static string x { get; set; }
  115. public static string y { get; set; }
  116. public static string z { get; set; }
  117.  
  118. }
  119.  
  120. public class MyClass {
  121. public string id;
  122. public string error;
  123. public Result result;
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement