Beispiel #1
0
    /// <summary>
    /// parse input data
    /// </summary>
    /// <param name="gameAction"></param>
    /// <param name="actionParam"></param>
    /// <param name="formater"></param>
    /// <param name="bShowLoading"></param>
    private void SocketRequest(GameAction gameAction, Google.Protobuf.IMessage pbData, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string   url = NetWriter.GetUrl();
            string[] arr = url.Split(new char[] { ':' });
            if (arr.Length != 2)
            {
                Debug.LogError("Url is error:" + url);
                return;
            }
            int nPort = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
        }
        gameAction.Head.MsgId = NetWriter.MsgId - 1;

        SocketPackage package = new SocketPackage();

        package.MsgId        = gameAction.Head.MsgId;
        package.ActionId     = gameAction.ActionId;
        package.ActionRespId = gameAction.Head.ActionRespId;
        package.Action       = gameAction;
        package.HasLoading   = bShowLoading;
        package.SendTime     = DateTime.Now;
        byte[] data = gameAction.Send(pbData);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
Beispiel #2
0
    /// <summary>
    /// parse input data
    /// </summary>
    /// <param name="gameAction"></param>
    /// <param name="actionParam"></param>
    /// <param name="formater"></param>
    /// <param name="bShowLoading"></param>
    private void SocketRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string   strUrl = NetWriter.GetUrl();
            string[] arr    = strUrl.Split(new char[] { ':' });
            int      nPort  = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
        }
        gameAction.Head.MsgId = NetWriter.MsgId - 1;

        SocketPackage package = new SocketPackage();

        package.MsgId      = gameAction.Head.MsgId;
        package.ActionId   = gameAction.ActionId;
        package.Action     = gameAction;
        package.HasLoading = bShowLoading;
        package.SendTime   = DateTime.Now;
        byte[] data = gameAction.Send(actionParam);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
Beispiel #3
0
    /// <summary>
    /// Socket消息发送
    /// </summary>
    /// <param name="gameAction">消息id</param>
    /// <param name="boby">内容</param>
    /// <param name="formater">解析协议对象</param>
    /// <param name="bShowLoading">是否显示loading界面</param>
    private void SocketRequest(GameAction gameAction, byte [] boby, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            Debug.LogError("与服务器断开连接,由于服务器无响应");
            Close();
            QueueEvent(EventDef.ServerColsed);
            return;
            //string strUrl = NetWriter.GetUrl();
            //string[] arr = strUrl.Split(new char[] { ':' });
            //int nPort = int.Parse(arr[1]);
            //mSocket = new SocketConnect(arr[0], nPort, formater);
        }
        gameAction.Head.MsgId = NetWriter.MsgId;

        SocketPackage package = new SocketPackage();

        package.MsgId      = (int)gameAction.Head.MsgId;
        package.ActionId   = (int)gameAction.ActionId;
        package.Action     = gameAction;
        package.HasLoading = bShowLoading;
        package.SendTime   = DateTime.Now;
        byte[] data = gameAction.Send(boby);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
Beispiel #4
0
    void NetworkUpdate()
    {
        if (localPlayers.Count == 0)
        {
            return;
        }
        // collect inputs for our players, send them to the server
        for (int i = 0; i < localPlayers.Count; i++)
        {
            localPlayers[i].CollectInputs();
        }
        // increase our frame tick
        clientTick++;

        NetWriter writer = NetworkManager.StartNetworkMessage("recv_client_inputs", thisNetworkID);

        writer.WriteByte(clientTick);
        writer.WriteByte((byte)localPlayers.Count);
        for (int i = 0; i < localPlayers.Count; i++)
        {
            writer.WriteFloat(localPlayers[i].input.driveInput);
            writer.WriteFloat(localPlayers[i].input.steerInput);
            writer.WriteFloat(localPlayers[i].input.useInput);
        }
        NetworkManager.SendMessageToServer(writer, NetworkCore.UnreliableSequencedMsg);
    }
    internal static void SpawnExplosion(Vector3 pos)
    {
        NetWriter writer = NetworkManager.StartNetworkMessage("fx_spawn", singleton.thisNetworkID);

        writer.WriteVector3(pos);
        NetworkManager.SendMessageToAllClients(writer, NetworkCore.UnreliableMsg, false);
    }
    internal static void CarKilled(BaseCar baseCar)
    {
        NetWriter writer = NetworkManager.StartNetworkMessage("fx_spawn", singleton.thisNetworkID);

        writer.WriteVector3(baseCar.transform.position);
        NetworkManager.SendMessageToAllClients(writer, NetworkCore.UnreliableMsg, false);
    }
    /// <summary>
    /// rebuild socket send hearbeat package
    /// </summary>
    public SocketPackage ReBuildHearbeat()
    {
        var writer = NetWriter.Instance;

        SprotoType.package headPack = new SprotoType.package()
        {
            protoId   = 2,
            session   = NetWriter.MsgId,
            errorcode = 0,
        };
        Sproto.SprotoPack pack      = new Sproto.SprotoPack();
        byte[]            headBytes = headPack.encode();
        writer.SetHeadBuffer(headBytes);
        writer.SetBodyData(new byte[0]);
        var data = writer.PostData();

        NetWriter.resetData();
        _hearbeatPackage = data;
        SocketPackage package = new SocketPackage();

        package.MsgId      = (int)headPack.session;
        package.ActionId   = 2;
        package.Action     = ActionFactory.Create(package.ActionId);
        package.SendTime   = DateTime.Now;
        package.HasLoading = false;
        return(package);
    }
Beispiel #8
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     //default url param
     writer.writeString("Pid", GameSetting.Instance.Pid);
     writer.writeInt32("UserId", (int)NetWriter.UserID);
     writer.writeString("Uname", actionParam.Get <string>("roleName"));
 }
Beispiel #9
0
        // Attempts to connect to a specified server with a given connection message
        public bool Connect(IPEndPoint Server, ConnectMessage ConnectionMessage)
        {
            // Initialise socket for TCP/IP communications
            Inner = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                // Try to connect
                Inner.Connect(Server);

                // Set up IO streams around the socket
                Stream = new NetworkStream(Inner);
                In     = new NetReader(Stream);
                Out    = new NetWriter(Stream);

                // Send off the initial connection message
                Send(ConnectionMessage);

                // Begin reading from the Server
                StartRead();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #10
0
 public IProtocol(Game game)
 {
     this.game = game;
     net       = (NetworkProcessor)game.Server;
     reader    = net.reader;
     writer    = net.writer;
 }
Beispiel #11
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     writer.writeInt32("roomID", (int)actionParam["roomID"]);
     writer.writeInt32("playerId", (int)actionParam["playerId"]);
     writer.writeInt32("num", (int)actionParam["num"]);
     writer.writeInt32("level", (int)actionParam["level"]);
 }
Beispiel #12
0
    /// <summary>
    /// parse input data
    /// </summary>
    /// <param name="url"></param>
    /// <param name="callback"></param>
    /// <param name="ud"></param>
    public void SocketRequest(int actionId, INetCallback callback, object userData, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string strUrl = NetWriter.GetUrl();
            Debug.Log("url" + strUrl);
            string[] arr   = strUrl.Split(new char[] { ':' });
            int      nPort = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort);
        }
        NetWriter writer = NetWriter.Instance;

        writer.writeInt32("actionId", actionId);
        byte[]        data    = NetWriter.Instance.PostData();
        SocketPackage package = new SocketPackage();

        package.FuncCallback = callback;
        package.UserData     = userData;
        package.MsgId        = NetWriter.MsgId - 1;
        package.ActionId     = actionId;
        package.HasLoading   = bShowLoading;
        package.SendTime     = DateTime.Now;
        NetWriter.resetData();

        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Request(data, package);
    }
    /// <summary>
    /// Destroys a network object. To be used in conjunction with NetworkInstantiate
    /// </summary>
    /// <param name="obj"></param>
    public void NetworkDestroy(NetObjectID obj)
    {
        NetworkID id = obj.netID;

        if (id.type != NetworkIDType.game)
        {
            Debug.LogError("Tried to destroy an ID that was not a game ID");
            return;
        }

        // remove all buffered messages assigned to this object
        foreach (BufferedMessage msg in obj.bufferedMessages)
        {
            bufferedMessages.Remove(msg);
        }
        // create a destroy event for all clients
        NetWriter writer = StartNetworkMessage("cl_NetworkDestroy", thisNetworkID);

        id.WriteBytes(writer);
        // notify all clients to destroy this object
        SendMessageToOtherClients(writer, NetworkCore.AllCostMsg, false);
        // finally destroy this object
        Destroy(obj.gameObject);
        // unregister this ID
        gameIDs[id.idNumber].left  = null;
        gameIDs[id.idNumber].right = false;
    }
        protected void Awake()
        {
            if (instance != null && instance != this)
            {
                Destroy(gameObject);
                return;
            }

            instance = this;
            w        = new NetWriter();
            NetLogFilter.CurrentLogLevel    = (int)logLevel;
            NetLogFilter.spew               = debugSpew;
            NetLogFilter.messageDiagnostics = messageDiagnostics;
            QualitySettings.vSyncCount      = 0;

            this.modules       = new Dictionary <Type, SteamNetworkModule>();
            initializedModules = new HashSet <Type>();

            isInitialized = false;

            var modules = GetComponentsInChildren <SteamNetworkModule>();

            foreach (var mod in modules)
            {
                AddModule(mod);
            }

            DontDestroyOnLoad(gameObject);
        }
Beispiel #15
0
    static int getMd5String(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes <string>(L, 1))
            {
                string arg0 = ToLua.ToString(L, 1);
                string o    = NetWriter.getMd5String(arg0);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes <byte[]>(L, 1))
            {
                byte[] arg0 = ToLua.CheckByteBuffer(L, 1);
                string o    = NetWriter.getMd5String(arg0);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: NetWriter.getMd5String"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Beispiel #16
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     if (actionParam.HasValue)
     {
         //自定对象参数格式
         isCustom = true;
         Request1001Pack requestPack = new Request1001Pack()
         {
             PageIndex = 1,
             PageSize  = 10
         };
         byte[] data = ProtoBufUtils.Serialize(requestPack);
         writer.SetBodyData(data);
     }
     else
     {
         isCustom = false;
         //默认url参数格式
         actionParam.Foreach((k, v) =>
         {
             writer.writeString(k, v.ToString());
             return(true);
         });
     }
 }
Beispiel #17
0
    void OnGUI()
    {
        // Now create any Controls you like, and they will be displayed with the custom Skin
        if (GUILayout.Button("Click Http"))
        {
            NetWriter.SetUrl("http://ph.scutgame.com/service.aspx");
            NetWriter writer = NetWriter.Instance;
            writer.writeString("PageIndex", "1");
            writer.writeInt32("PageSize", 10);
            Net.Instance.Request(1001, httpCallback, null);
        }



        // Any Controls created here will use the default Skin and not the custom Skin
        if (GUILayout.Button("Click Socket"))
        {
            ///////
            Debug.Log("set url first");
            NetWriter.SetUrl("ph.scutgame.com:9001");
            NetWriter writer = NetWriter.Instance;
            writer.writeString("PageIndex", "1");
            writer.writeInt32("PageSize", 10);
            Net.Instance.Request(1001, httpCallback, null);
        }
    }
Beispiel #18
0
    protected override void DecodePackage(NetReader reader)
    {
        responsePack = new Response1004Packet()
        {
            Result = reader.getInt()
        };
        if (responsePack.SuccessOrUpdate)
        {
            responsePack.LoginResp = JsonUtil.DeserializeObject <LoginResp>(reader.readString());
            if (responsePack.Success)
            {
                UIModelMgr.Instance.GetModel <UIMainModel>().SetShareInfos(responsePack.LoginResp.ShareInfos);
                NetWriter.setUserID(ulong.Parse(responsePack.LoginResp.UserId));
                NetWriter.setSessionID(responsePack.LoginResp.SessionId);

                Debug.Log("SessionId ================= " + responsePack.LoginResp.SessionId);

                Net.Instance.ReBuildHearbeat();
                UIModelMgr.Instance.GetModel <UIGameModel>().ClearGameEndDatas();
            }
            else
            {
                UIDialogMgr.Instance.ShowDialog(responsePack.Result, delegate(GameObject go) { Application.OpenURL(responsePack.LoginResp.ApkUpdateWebsite); });
            }
        }
        else
        {
            UIDialogMgr.Instance.ShowDialog(responsePack.Result);
        }
    }
        public override void Connect( IPAddress address, int port )
        {
            socket = new Socket( address.AddressFamily, SocketType.Stream, ProtocolType.Tcp );
            try {
                socket.Connect( address, port );
            } catch( SocketException ex ) {
                ErrorHandler.LogError( "connecting to server", ex );
                game.Disconnect( "&eUnable to reach " + address + ":" + port,
                                "Unable to establish an underlying connection" );
                Dispose();
                return;
            }

            NetworkStream stream = new NetworkStream( socket, true );
            reader = new NetReader( stream );
            writer = new NetWriter( stream );
            gzippedMap = new FixedBufferStream( reader.buffer );
            envMapAppearanceVer = 2;
            blockDefinitionsExtVer = 2;
            needD3Fix = false;

            Disconnected = false;
            receivedFirstPosition = false;
            lastPacket = DateTime.UtcNow;
            game.WorldEvents.OnNewMap += OnNewMap;

            MakeLoginPacket( game.Username, game.Mppass );
            SendPacket();
            lastPacket = DateTime.UtcNow;
        }
Beispiel #20
0
    /// <summary>
    /// 每一帧被调用多次,enabled=false时禁用
    /// </summary>
    void OnGUI()
    {
        int cwidth  = Screen.width / 2;
        int cheight = Screen.height / 2;
        var boxPos  = new Rect(cwidth - 110, cheight - 160, 240, 120);

        GUI.Box(boxPos, "");
        GUI.Label(new Rect(cwidth - 100, cheight - 150, 100, 22), "User:"******"Password:"******"Regist"))
        {
            //TODO:登录服务器分布式访问
            //NetWriter.SetUrl("http://pass.scutgame.com/", ResponseContentType.Json, true);
            //Debug.Log("Started to access login server, resp-type:" + NetWriter.ResponseContentType.ToString());

            NetWriter.SetUrl("127.0.0.1:9001");
            Net.Instance.Send((int)ActionType.Regist, RegistCallback, null);
        }

        if (GUI.Button(new Rect(cwidth, cheight - 80, 80, 22), "Login"))
        {
            NetWriter.SetUrl("127.0.0.1:9001");

            Debug.Log(NetWriter.GetUrl());
            GameSetting.Instance.Pid      = user;
            GameSetting.Instance.Password = pwd;
            Net.Instance.Send((int)ActionType.Login, LoginCallback, null);
        }
    }
 void Init()
 {
     if (hasInit)
     {
         return;
     }
     writer    = new NetWriter();
     reader    = new NetReader();
     writeData = new byte[NetworkCore.MAX_DATA_SIZE];
     sceneIDs  = new Pair <NetObjectID, bool> [256];
     gameIDs   = new Pair <NetObjectID, bool> [256];
     for (int i = 0; i < 256; i++)
     {
         sceneIDs[i] = new Pair <NetObjectID, bool>();
         gameIDs[i]  = new Pair <NetObjectID, bool>();
     }
     HasJoinedGame = false;
     // load up all the network functions
     RegisterAllFunctions();
     // load up the prefabs
     RegisterAllPrefabs();
     // link into the scene loading
     SceneManager.sceneLoaded += OnSceneLoaded;
     // notify all objects in this scene that the network scene has loaded
     //OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single);
     hasInit = true;
 }
Beispiel #22
0
    private IEnumerator HttpGetRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool showLoading)
    {
        string url = NetWriter.GetUrl();

        byte[]      postData    = gameAction.Send(actionParam);
        DateTime    start       = DateTime.Now;
        HttpPackage httpPackage = new HttpPackage();

        httpPackage.WwwObject = NetWriter.IsGet ? new WWW(string.Format("{0}?{1}", url, Encoding.UTF8.GetString(postData))) : new WWW(url, postData);
        httpPackage.ActionId  = gameAction.ActionId;
        httpPackage.Action    = gameAction;
        httpPackage.Reader    = new NetReader(formater);

        if (RequestNotify != null && showLoading)
        {
            RequestNotify(Net.Status.eStartRequest);
        }

        yield return(httpPackage.WwwObject);

        if (RequestNotify != null && showLoading)
        {
            RequestNotify(Net.Status.eEndRequest);
        }
        TimeSpan tsStart = new TimeSpan(start.Ticks);
        TimeSpan tsEnd   = new TimeSpan(DateTime.Now.Ticks);
        TimeSpan ts      = tsEnd.Subtract(tsStart).Duration();

        if (ts.Seconds > OVER_TIME)
        {
            httpPackage.IsOverTime = true;
        }
        OnHttpRespond(httpPackage);
    }
Beispiel #23
0
    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(10, 10, 500, 100));
        GUILayout.BeginHorizontal();
        // Now create any Controls you like, and they will be displayed with the custom Skin
        if (GUILayout.Button("Get ranking for Http"))
        {
            NetWriter.SetUrl("http://ph.scutgame.com/service.aspx");
            Net.Instance.Send((int)ActionType.RankSelect, OnRankingCallback, GetReuqest1001());
        }
        GUILayout.Space(20);
        // Any Controls created here will use the default Skin and not the custom Skin
        if (GUILayout.Button("Get ranking for Socket"))
        {
            NetWriter.SetUrl("ph.scutgame.com:9001");
            Net.Instance.Send((int)ActionType.RankSelect, OnRankingCallback, GetReuqest1001());
        }
        GUILayout.Space(20);
        if (GUILayout.Button("Add ranking for Socket"))
        {
            NetWriter.SetUrl("ph.scutgame.com:9001");
            var actionParam = new ActionParam(new RankData()
            {
                Score = 90, UserName = "******" + index
            });
            index++;
            Net.Instance.Send((int)ActionType.RankAdd, OnRankAddCallback, actionParam);
        }

        GUILayout.EndHorizontal();
        GUILayout.EndArea();
        OnRankGUI();
    }
Beispiel #24
0
    public byte[] Send(object userData)
    {
        NetWriter writer = NetWriter.Instance;

        SetActionHead(writer);
        SendParameter(writer, userData);
        return(writer.PostData());
    }
Beispiel #25
0
    public byte[] Send(byte[] bs)
    {
        NetWriter writer = NetWriter.Instance;

        SetActionHead(writer);
        writer.SetBodyData(bs);
        return(writer.PostData());
    }
Beispiel #26
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     if (actionParam.HasValue)
     {
         MahJongGameAction requestPack = actionParam.GetValue <MahJongGameAction>();
         writer.writeString("GameAction", JsonUtil.SerializeObject(requestPack));
     }
 }
Beispiel #27
0
 internal void SendCarVisuals(ConnectionData conn)
 {
     for (int i = 0; i < cars.Length; i++)
     {
         NetWriter writer = cars[i].PackVisuals();
         NetworkManager.SendMessageToClient(writer, NetworkCore.ReliableSequencedMsg, conn.connectionId);
     }
 }
Beispiel #28
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     if (actionParam.HasValue)
     {
         RoomMsgInfo requestPack = actionParam.GetValue <RoomMsgInfo>();
         writer.writeString("RoomMessage", JsonUtil.SerializeObject(requestPack));
     }
 }
Beispiel #29
0
    static int IsSocket(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        bool o = NetWriter.IsSocket();

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Beispiel #30
0
    public void HttpRequest(int actionId, INetCallback callback, object userData, bool bShowLoading)
    {
        NetWriter writer = NetWriter.Instance;

        writer.writeInt32("actionId", actionId);
        StartCoroutine(Http.GetRequest(writer.generatePostData(), userData, actionId, callback, this, bShowLoading));
        NetWriter.resetData();
    }
    public static void SendMessageToClient(NetWriter _writer, int channelType, int clientId)
    {
        writer.StopWriting();
        int writtenSize = _writer.GetWrittenBytes();

        byte[] rawData = _writer.GetRawData();
        NetworkCore.singleton.SendRawToClient(clientId, channelType, rawData, writtenSize);
    }
Beispiel #32
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     writer.writeInt32("MobileType", GameSetting.Instance.MobileType);
     writer.writeInt32("GameID", GameSetting.Instance.GameID);
     writer.writeString("RetailID", GameSetting.Instance.RetailID);
     writer.writeString("ClientAppVersion", GameSetting.Instance.ClientAppVersion);
     writer.writeInt32("ScreenX", GameSetting.Instance.ScreenX);
     writer.writeInt32("ScreenY", GameSetting.Instance.ScreenY);
     writer.writeString("DeviceID", GameSetting.Instance.DeviceID);
     writer.writeInt32("ServerID", GameSetting.Instance.ServerID);
 }
Beispiel #33
0
 protected override void SendParameter(NetWriter writer, ActionParam userData)
 {
     //自定对象参数格式
     //Request1001Pack requestPack = new Request1001Pack()
     //{
     //    PageIndex = 1,
     //    PageSize = 10
     //};
     //byte[] data = ProtoBufUtils.Serialize(requestPack);
     //writer.SetBodyData(data);
     //Debug.Log("Action1001: SendParameter() DONE!");
 }
Beispiel #34
0
 protected override void SetActionHead(NetWriter writer)
 {
     MessagePack headPack = new MessagePack()
     {
         MsgId = Head.MsgId,
         ActionId = ActionId,
         SessionId = Head.SessionId,
         UserId = Head.UserId
     };
     byte[] data = ProtoBufUtils.Serialize(headPack);
     writer.SetHeadBuffer(data);
     writer.SetBodyData(null);
 }
Beispiel #35
0
    protected override void SendParameter(NetWriter writer, ActionParam actionParam)
    {
        //TODO:登录服务器获取账号
        //writer.writeString("Handler", "Passport");
        //writer.writeString("IMEI", GameSetting.Instance.DeviceID);

        writer.writeInt32("MobileType", GameSetting.Instance.MobileType);
        writer.writeInt32("GameID", GameSetting.Instance.GameID);
        writer.writeString("RetailID", GameSetting.Instance.RetailID);
        writer.writeString("ClientAppVersion", GameSetting.Instance.ClientAppVersion);
        writer.writeInt32("ScreenX", GameSetting.Instance.ScreenX);
        writer.writeInt32("ScreenY", GameSetting.Instance.ScreenY);
        writer.writeString("DeviceID", GameSetting.Instance.DeviceID);
        writer.writeInt32("ServerID", GameSetting.Instance.ServerID);
    }
Beispiel #36
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     //default url param
     writer.writeString("UserName", actionParam.Get<string>("roleName"));
     writer.writeString("Sex",  actionParam.Get<string>("Sex"));
     writer.writeString("HeadID",  actionParam.Get<string>("HeadID"));
     writer.writeString("RetailID", GameSetting.Instance.RetailID);
     writer.writeString("Pid", GameSetting.Instance.Pid);
     writer.writeInt32("MobileType", GameSetting.Instance.MobileType);
     writer.writeInt32("ScreenX", GameSetting.Instance.ScreenX);
     writer.writeInt32("ScreenY", GameSetting.Instance.ScreenY);
     writer.writeString("ClientAppVersion", GameSetting.Instance.ClientAppVersion);
     writer.writeInt32("GameType", GameSetting.Instance.GameID);
     writer.writeInt32("ServerID", GameSetting.Instance.ServerID);
 }
Beispiel #37
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     string pwd = new DESAlgorithmNew().EncodePwd(GameSetting.Instance.Password, GameSetting.ClientPasswordKey);
     //default url param
     writer.writeInt32("MobileType", GameSetting.Instance.MobileType);
     writer.writeString("Pid", GameSetting.Instance.Pid);
     writer.writeString("Pwd", pwd);
     writer.writeString("DeviceID", GameSetting.Instance.DeviceID);
     writer.writeInt32("ScreenX", GameSetting.Instance.ScreenX);
     writer.writeInt32("ScreenY", GameSetting.Instance.ScreenY);
     writer.writeString("RetailID", GameSetting.Instance.RetailID);
     writer.writeInt32("GameType", GameSetting.Instance.GameID);
     writer.writeInt32("ServerID", GameSetting.Instance.ServerID);
     writer.writeString("RetailUser", "");
     writer.writeString("ClientAppVersion", GameSetting.Instance.ClientAppVersion);
 }
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     if (actionParam.HasValue)
     {
         //自定对象参数格式
         isCustom = true;
         var rankData = actionParam.GetValue<RankData>();
         byte[] data = ProtoBufUtils.Serialize(rankData);
         writer.SetBodyData(data);
     }
     else
     {
         isCustom = false;
         writer.writeString("UserName", "Jon");
         writer.writeInt32("Score", 100);
     }
 }
        public override void Connect( IPAddress address, int port )
        {
            socket = new Socket( address.AddressFamily, SocketType.Stream, ProtocolType.Tcp );
            try {
                socket.Connect( address, port );
            } catch( SocketException ex ) {
                ErrorHandler.LogError( "connecting to server", ex );
                game.Disconnect( "&eUnable to reach " + address + ":" + port,
                                "Unable to establish an underlying connection" );
                Dispose();
                return;
            }

            NetworkStream stream = new NetworkStream( socket, true );
            reader = new NetReader( stream );
            writer = new NetWriter( stream );
            gzippedMap = new FixedBufferStream( reader.buffer );
            MakeLoginPacket( game.Username, game.Mppass );
            SendPacket();
        }
Beispiel #40
0
 protected override void SendParameter(NetWriter writer, object userData)
 {
     if (isCustom)
     {
         //自定对象参数格式
         Request1001Pack requestPack = new Request1001Pack()
         {
             PageIndex = 1,
             PageSize = 10
         };
         byte[] data = ProtoBufUtils.Serialize(requestPack);
         writer.SetBodyData(data);
     }
     else
     {
         //默认url参数格式
         writer.writeInt32("PageIndex", 1);
         writer.writeInt32("PageSize", 10);
     }
 }
Beispiel #41
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     if (actionParam.HasValue)
     {
         //自定对象参数格式
         isCustom = true;
         Request1001Pack requestPack = actionParam.GetValue<Request1001Pack>();
         byte[] data = ProtoBufUtils.Serialize(requestPack);
         writer.SetBodyData(data);
     }
     else
     {
         isCustom = false;
         //默认url参数格式
         actionParam.Foreach((k, v) =>
         {
             writer.writeString(k, v);
             return true;
         });
     }
 }
Beispiel #42
0
 protected override void SendParameter(NetWriter writer, ActionParam userData)
 {
     //byte[] data = new byte[0];
     //writer.SetBodyData(data);
 }
Beispiel #43
0
 protected abstract void SendParameter(NetWriter writer, object userData);
Beispiel #44
0
 protected override void SendParameter(NetWriter writer, ActionParam userData)
 {
 }
Beispiel #45
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     //TODO:登录服务器获取账号
     //writer.writeString("Handler", "Passport");
     //writer.writeString("IMEI", GameSetting.Instance.DeviceID);
 }
Beispiel #46
0
 protected virtual void SetActionHead(NetWriter writer)
 {
     writer.writeInt32("actionId", ActionId);
 }
Beispiel #47
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     //default url param
 }
Beispiel #48
0
 protected abstract void SendParameter(NetWriter writer, ActionParam actionParam);
Beispiel #49
0
 protected override void SendParameter(NetWriter writer, object userData)
 {
     writer.writeString("UserName", "Jon");
     writer.writeInt32("Score", 100);
 }
Beispiel #50
0
 protected override void SendParameter(NetWriter writer, ActionParam actionParam)
 {
     writer.writeString("UserName", "Jon");
     writer.writeInt32("Score", 100);
 }
Beispiel #51
0
 protected override void SendParameter(NetWriter writer, ActionParam userData)
 {
     byte[] data = ProtoBufUtils.Serialize(userData.GetValue<LoginMessage>());
     writer.SetBodyData(data);
 }