void SendData(int cmd, string info, NetCallBack callback) { if (Checker.SendCheker.ContainsKey((PROTOCOL)cmd)) { ProtocolChecker checker = Checker.SendCheker[(PROTOCOL)cmd]; callback += (json) => { checker.canSend = true; }; //< 중복해서 전송이 가능하면 또 전송 if (checker.canDuplicate) { netBase.SendData(cmd, info, callback); } else { //< 중복이 안된다면 현재 전송이 가능할때만 전송 if (checker.canSend) { netBase.SendData(cmd, info, callback); } } //< 전송 불가능으로 대입 checker.canSend = false; } }
private IEnumerator SendTo(string request, NetCallBack callback) { WWWForm form = new WWWForm(); #if NETWORK_ENCRYPT Debug.Log("NetworkBase SendTo() : " + m_szActionUrl + "?enc=" + jsonData); jsonData = NetworkBase.Scecurity.Encrypt(jsonData); #endif form.AddField("enc", request); Debug.Log(address + "?enc=" + request); WWW www = new WWW(address, form); www.threadPriority = ThreadPriority.High; yield return(www); if (www.error != null) { Debug.Log("www error : " + www.error); } else { if (www.isDone) { DoRecieve(request, Encoding.UTF8.GetString(www.bytes), callback); } else { yield return(www); } } }
public static void ListenerMsg(ProtoDefine protoType, NetCallBack callBack) { if (!m_EventTable.ContainsKey(protoType)) { m_EventTable.Add(protoType, null); } m_EventTable[protoType] = (NetCallBack)m_EventTable[protoType] + callBack; }
public void SendData(int cmd, string info, NetCallBack callback) { if (!NetworkCheck()) { return; } sb.Remove(0, sb.Length); sb.AppendFormat("{{\"cmd\":{0}, \"info\":[{1}]}}", cmd, info); StartCoroutine(SendTo(sb.ToString(), callback)); }
public static void RemoveListenerMsg(ProtoDefine protoType, NetCallBack callBack) { if (m_EventTable.ContainsKey(protoType)) { m_EventTable[protoType] = (NetCallBack)m_EventTable[protoType] - callBack; if (m_EventTable[protoType] == null) { m_EventTable.Remove(protoType); } } }
public static void DispatcherMsg(NetMsgData msgData) { ProtoDefine protoType = (ProtoDefine)msgData.ProtoId; Delegate d; if (m_EventTable.TryGetValue(protoType, out d)) { NetCallBack callBack = d as NetCallBack; if (callBack != null) { callBack(msgData.ProtoData); } } }
private void DoRecieve(string sendString, string recieveData, NetCallBack callback) { lock (this) { #if NETWORK_ENCRYPT recieveData = NetworkBase.Scecurity.Decrypt(recieveData); #endif JSONObject jsonObject = new JSONObject(recieveData); //Debug.Log(jsonObject); try { if (jsonObject != null) { if (jsonObject["cmd"] != null || jsonObject["errno"].n != 0) { if (netReceiver != null) { netReceiver(jsonObject, callback); } } else { //Debug.LogError("cmd == null"); // TODO error 비정상데이타처리 throw new Exception("cannot parsing"); } } else { // TODO error 비정상데이타처리 throw new Exception("cannot parsing"); } } catch (Exception e) { Debug.LogError(e.ToString()); } } }
/// <summary> /// 스크립트로 가장먼저 서버의 ack 를 받는 코드 /// </summary> /// <param name="Ans"></param> public void Receiver(JSONObject jsonObject, NetCallBack callback) { PROTOCOL protocol = (PROTOCOL)jsonObject["cmd"].n; Debug.Log(protocol + ": " + jsonObject.ToString()); int errno = (int)jsonObject["errno"].n; if (errno == 0) { switch (protocol) { case PROTOCOL.P_SERVICE_INFO: P_SERVICE_INFO(jsonObject); break; case PROTOCOL.P_USER_LOGIN: P_USER_LOGIN(jsonObject); break; case PROTOCOL.P_USER_INFO: P_USER_INFO(jsonObject); break; case PROTOCOL.P_USER_LIST: P_USER_LIST(jsonObject); break; case PROTOCOL.P_USER_SETPW: P_USER_SETPW(jsonObject); break; case PROTOCOL.P_USER_UPGRADE: P_USER_UPGRADE(jsonObject); break; case PROTOCOL.P_USER_NOTIFY: P_USER_NOTIFY(jsonObject); break; case PROTOCOL.P_USER_NICKNAME: P_USER_NICKNAME(jsonObject); break; case PROTOCOL.P_GAME_START: P_GAME_START(jsonObject); break; case PROTOCOL.P_GAME_RESULT: P_GAME_RESULT(jsonObject); break; case PROTOCOL.P_GAME_LOG: P_GAME_LOG(jsonObject); break; case PROTOCOL.P_GAME_REVENGE: P_GAME_REVENGE(jsonObject); break; default: Debug.LogError("not found protocol"); break; } } else { // 팝업으로 에러 띄움 //ShowErrorPopup(errno); UIManager.instance.CreateOKPopup(errno); Debug.Log("ErrNo : " + protocol.ToString() + "(" + errno + ")"); } if (callback != null) { callback(jsonObject); } }
public void P_USER_LOGIN(string device_id, NetCallBack callback = null) { info.Remove(0, info.Length); info.AppendFormat("\"{0}\"", Encoding(device_id)); SendData((int)PROTOCOL.P_USER_LOGIN, info.ToString(), callback); }
public void P_SERVICE_INFO(NetCallBack callback = null) { info.Remove(0, info.Length); SendData((int)PROTOCOL.P_SERVICE_INFO, info.ToString(), callback); }
public void P_GAME_REVENGE(ulong target_id, ulong game_id, NetCallBack callback = null) { info.Remove(0, info.Length); info.AppendFormat("{0},{1},{2}", DataManager.instance.GetID(), target_id, game_id); SendData((int)PROTOCOL.P_GAME_REVENGE, info.ToString(), callback); }
public void P_GAME_LOG(NetCallBack callback = null) { info.Remove(0, info.Length); info.AppendFormat("{0}", DataManager.instance.GetID()); SendData((int)PROTOCOL.P_GAME_LOG, info.ToString(), callback); }
public void P_GAME_RESULT(ulong game_id, byte try_count, NetCallBack callback = null) { info.Remove(0, info.Length); info.AppendFormat("{0},{1},{2}", DataManager.instance.GetID(), game_id, try_count); SendData((int)PROTOCOL.P_GAME_RESULT, info.ToString(), callback); }
public void P_USER_NICKNAME(string name, NetCallBack callback = null) { info.Remove(0, info.Length); info.AppendFormat("{0},\"{1}\"", DataManager.instance.GetID(), Encoding(name)); SendData((int)PROTOCOL.P_USER_NICKNAME, info.ToString(), callback); }
public void P_USER_UPGRADE(byte type, NetCallBack callback = null) { info.Remove(0, info.Length); info.AppendFormat("{0},{1}", DataManager.instance.GetID(), type); SendData((int)PROTOCOL.P_USER_UPGRADE, info.ToString(), callback); }
public void P_USER_SETPW(string password, NetCallBack callback = null) { info.Remove(0, info.Length); info.AppendFormat("{0},\"{1}\"", DataManager.instance.GetID(), password); SendData((int)PROTOCOL.P_USER_SETPW, info.ToString(), callback); }