Example #1
0
    //	public void Send (string method, string data, char chars = '|')
    //	{
    //		if (socket == null || !socket.Connected)
    //		{
    //			Log.debug ("Socket is Closed");
    //			return;
    //		}
    //		VoSocket vo = new VoSocket ();
    //		byte[] body = vo.ToBytes (method, data, chars);
    //		byte[] head = System.BitConverter.GetBytes (body.Length);
    //		byte[] d = new byte[VoPackage.HEAD_LEN + body.Length];
    //		Array.Copy (head, 0, d, 0, head.Length);
    //		Array.Copy (body, 0, d, VoPackage.HEAD_LEN, body.Length);
    //		Log.debug ("SocketSend:" + method);
    //		socket.Send (d, SocketFlags.None);
    //	}

    public void Send(string method, Dictionary <string, object> data)
    {
//		Debug.LogError ("Send -->> : "+method);
        if (socket == null || !socket.Connected)
        {
//			Debug.LogError ("Socket error ->> :" + socket.Connected);
//			Log.debug ("Socket is Closed");
//			ViewManager.inst.ShowAlert (Tools.GetMessageById ("14004"), ReConnect, false);
            return;
        }
        try
        {
            VoSocket vo   = new VoSocket();
            byte[]   body = vo.ToBytes(method, data);
            byte[]   head = System.BitConverter.GetBytes(body.Length);
            byte[]   d    = new byte[VoPackage.HEAD_LEN + body.Length];
            Array.Copy(head, 0, d, 0, head.Length);
            Array.Copy(body, 0, d, VoPackage.HEAD_LEN, body.Length);
//			if (vo.method != NetBase.SOCKET_PING && this.type != 1)
//				Log.debug ("SocketSend[" + this.ip + "]:" + JsonUtility.ToJson (vo));
            socket.Send(d, SocketFlags.None);
        }
        catch (Exception e)
        {
//			Debug.LogError (e.Message.ToString ());
            Interlocked.Exchange(ref isConnectStatus, -1);
            return;
        }
    }
Example #2
0
 public void Excute(VoSocket vo)
 {
     if (onEvent != null)
     {
         onEvent(vo);
     }
 }
Example #3
0
    private static void sync(VoSocket vo)
    {
        //Log.debug("收到服务器的间隔时间:" + ( System.DateTime.Now.Ticks - t ));

        t = System.DateTime.Now.Ticks;
        invoke(() => {
            Dictionary <string, object> map = vo.data as Dictionary <string, object>;
            object[] objs = map["ops"] as object[];
            double offset = Math.Abs(t2 - (double)map["time"]);
            //			if(offset > 101 || offset < 99){
            //				MediatorSystem.log("error", offset);
            //			}
            //			MediatorSystem.log("data", offset);

            t2 = (double)map["time"];
            if (map.ContainsKey("map_data"))
            {
                mapData.Add(map["map_data"]);
            }
            if (-1 != voId && voId + 1 != (int)map["sync_num"])
            {
                throw new Exception("voId对不上了! 请检查!");
            }
            voId = (int)map["sync_num"];
            syncOne(objs);
            //	List<object> list = new List<object> ((object[])data ["sync"]);
        });
    }
Example #4
0
    private static void matchRePlay(VoSocket vo)
    {
        Debug.Log("matchRePlay");
        Dictionary <string, object> data = vo.data as Dictionary <string, object>;

        FightMain.instance.testPanel.runServer2((object[])data["frame_list"], (object[])data["map_data_list"], (int)data["start"], (int)data["end"]);
    }
Example #5
0
 private static void onNoteRoom(VoSocket vo)
 {
     Debug.Log("onNoteRoom");
     if (FightMain.fightTest)
     {
         FightMain.instance.onStart();
     }
     else
     {
         FightMain.instance.clear();
     }
 }
Example #6
0
    private static void initUser(VoSocket vo)
    {
        voId = -1;
        FightMain.instance.lobby.hide();
        FightMain.instance.cc     = 3;
        FightMain.instance.isPlay = true;
        Debug.Log("recevie:initUser");
        Dictionary <string, object> data = (Dictionary <string, object>)vo.data;
        string uid       = data["uid"].ToString();
        int    teamIndex = (int)data["teamIndex"];

        PlayerData.instance.uid = uid;
        FightMain.instance.addUser(uid, teamIndex);
        mapData.Clear();
    }
Example #7
0
    public void Socket_loginBack(VoSocket vo)
    {
        if (vo.data is Boolean)
        {
            //					Debug.LogError("SOCKET_LOGIN false");
            NetSocket.inst.socketLogin = false;
        }
        else
        {
            //					Debug.LogError("SOCKET_LOGIN true");
            //				Log.debug ("Socket Login - " + vo.data.ToString ());
            NetSocket.inst.socketLogin = true;            //Convert.ToBoolean (vo.data);

            Dictionary <string, object> re = (Dictionary <string, object>)vo.data;
            bool isBattle = Convert.ToBoolean(re ["in_battle"]);
            if (isBattle)
            {
                int        typeId     = (int)re ["type"];
                ModelFight fightModel = ModelManager.inst.fightModel;
                fightModel.isLeader = true;
                if (typeId == 1)
                {
                    fightModel.fightType = ModelFight.FIGHT_MATCH;
                }
                else if (typeId == 2)
                {
                    fightModel.fightType = ModelFight.FIGHT_MATCHTEAM;
                }
                else if (typeId == 3)
                {
                    fightModel.fightType = ModelFight.FIGHT_FREEMATCH1;
                }
                DispatchManager.inst.Dispatch(new MainEvent(MainEvent.FIGHT_ING));
            }
            else
            {
            }
        }
        Main.inst.Socket_Listen();
    }
Example #8
0
    private void Socket_Check(float time)
    {
        if (test)
        {
            if (package.Count >= 2)
            {
                test = false;
            }
        }
        if (test)
        {
            return;
        }
        index++;
//		Debug.LogError ("Socket_Check -->> :: " + package.Count);
        if (package.Count >= 1)
        {
            count    = package.Count;
            maxCount = Math.Max(count, maxCount);
//            long offset = ( System.DateTime.Now.Ticks - tick ) / 10000;

            //			if (0 != tick) {
            //				MediatorSystem.log("socketUpdate", offset);
            //
            //				if (offset >= 150) {
            //					MediatorSystem.log("socket大", offset);
            //				}
            //
            //				if (offset <= 50) {
            //					MediatorSystem.log("socket小", offset);
            //				}
            //
            //
            //			}

            tick = System.DateTime.Now.Ticks;
        }
//		Debug.LogError ("Socket_Check");
        MediatorSystem.log("count", package.Count + "   " + count + "    " + maxCount);
        while (package.Count != 0)
        {
            VoPackage vo = null;
            lock (package) {
                vo = package[0];
                package.Remove(vo);
            }
            if (vo.isClear)
            {
//                LogMessage.instance.text.text += "此vo已经被清除过了!";
                continue;
            }
            VoSocket v = new VoSocket();
//            MediatorSystem.timeStart("SockettoDatas");
            v.toDatas(vo.body);
//            MediatorSystem.getRunTime("SockettoDatas");
//			Debug.LogError ("re -->> :: " + v.method);
//			if (v.method == NetBase.SOCKET_LOGIN) {
//				Check_Ping ();
//			}
//            if(v.method != NetBase.SOCKET_PING && v.method != "sync")
//                Log.debug("SocketReceive[" + this.ip + "]:" + JsonUtility.ToJson(v));
            if (!vo.isClear)
            {
                if (call.ContainsKey(v.method))
                {
//					Debug.LogError (v.method);
                    SocketListener sl = call[v.method];
                    //try {
//                    MediatorSystem.timeStart("execSocketData");
                    sl.Excute(v);
//                    MediatorSystem.getRunTime("execSocketData");
                    //} catch(Exception e) {
                    //    Debug.Log(e.HelpLink);
                    //}
                }
            }
            else
            {
//                Log.debug("Socket Data Is Clear");
            }
            vo.Clear();
        }
        if (index % 500 == 0)
        {
            maxCount = 0;
            tick2    = 0;
        }
    }
Example #9
0
 private void SOCKET_LOGIN_re(VoSocket vo)
 {
     NetSocket.inst.socketLogin = true;
     NetSocket.inst.RemoveListener(NetBase.SOCKET_LOGIN);
 }
Example #10
0
 private static void getRoomInfo(VoSocket vo)
 {
     //FightMain.instance.lobby.updateRoomInfo((Dictionary<string, object>)vo.data);
 }
Example #11
0
 private static void stopMatch(VoSocket vo)
 {
     FightMain.instance.equalPanel.fightId.text = FightMain.instance.id = ((Dictionary <string, object>)vo.data)["id"].ToString();
     Debug.Log("stopMatch");
     FightMain.instance.onStart();
 }