Example #1
0
    public void readMessage(ErlKVMessage message)
    {
        string str = message.Cmd;
        Log.Info (str);
        Log.Info (message.toJsonString ());
        BaseFPort bf = null;
        foreach (string key in BaseFPort.portDict.Keys) {
            if (key.Contains (str)||str.Contains(key)) {
                bf = BaseFPort.portDict [key];
            }
        }
        if (bf != null) {
            bf.erlConnect = this.erlConnect;
            bf.read (message);
        } else {
            switch (str) {
            case "echo":
                ErlKVMessage _messag = new ErlKVMessage ("r_ok");
                _messag.addValue (null, new ErlInt (message.getPort ()));
                base.send (this.erlConnect, _messag);
                break;
            case "/yxzh/home_port/get_info":
                ErlKVMessage msg = new ErlKVMessage ("r_ok");
                msg.addValue (null, new ErlInt (message.getPort ()));
                msg.addValue ("msg", new ErlAtom ("home_not_open"));
                base.send (this.erlConnect, msg);
                break;
            case "/yxzh/ww_guild_child_fore_port/get_switch":
                ErlKVMessage msg1 = new ErlKVMessage ("r_ok");
                msg1.addValue (null, new ErlInt (message.getPort ()));
                msg1.addValue ("msg", new ErlByte (1));
                base.send (this.erlConnect, msg1);
                break;
            case "/yxzh/question/get_questions":
            case "/yxzh/week_award/init":
            case "/yxzh/expedition/get_base_info":
            case "/yxzh/opentask/get_opentasks":
            case "/yxzh/title/get_title":
            case "/yxzh/affiche/get_active_notice":

                //break;
            default:
                //Log.Error (message.Cmd);
                String strValue = ConfigHelper.GetAppConfig (message.Cmd);
                ErlKVMessage dmsg = new ErlKVMessage ("r_ok");
                dmsg.addValue (null, new ErlInt (message.getPort ()));
                ErlType[] et = StringKit.strToErlTypeArray (strValue);
                ErlArray ea = new ErlArray (et);
                dmsg.addValue ("msg", ea);
                base.send (this.erlConnect, dmsg);
                break;
            }
        }
    }
Example #2
0
    public override void erlReceive(Connect connect, ErlKVMessage message)
    {
        if (!MiniConnectManager.IsRobot )
        {
            try
            {

               // Log.debug("===============this is socketReceive! cmd=" + message.Cmd + " jsonString " + message.toJsonString(),true);
            }
            catch (Exception exception)
            {
                //Log.debug(" =================== : " + exception.ToString(),true);
            }
        }
        string cmd = message.Cmd;
        switch (cmd)
        {
            case "r_ok":
            case "r_err":
            {
                int port = message.getPort();
                ErlEntry entry = this.removeReciveFun(port);
                if ((entry == null) || (entry.receiveFun == null))
                {
                    return;
                }
                entry.receiveFun(connect, message);
                break;
            }
            default:
                message.addValue("cmd", new ErlString(cmd));
                this.defaultHandle(connect, message);
                break;
        }
    }
Example #3
0
    override public void erlReceive(Connect connect, ErlKVMessage message)
    {
        if (!MiniConnectManager.IsRobot && Debug.isDebugBuild == true)
        {
            if (message.Cmd == "match")
            {
                Debug.Log("this is socketReceive! cmd=" + message.Cmd);
            }
            else
            {
                Debug.Log("this is socketReceive! cmd=" + message.Cmd + " jsonString " + message.toJsonString());
            }
        }

        string cmd = message.Cmd;

        if (cmd == "r_ok" || cmd == "r_err")
        {
            int      port  = message.getPort();       // 获取流水号
            ErlEntry entry = removeReciveFun(port);
            if (entry == null || entry.receiveFun == null)
            {
                return;
            }
            entry.receiveFun(connect, message);
        }
        else
        {                                                // 服务器的广播消息
            message.addValue("cmd", new ErlString(cmd)); // 为js服务的代码
            defaultHandle(connect, message);
        }
    }
Example #4
0
    public override void read(ErlKVMessage message)
    {
        string str = message.Cmd;
        switch (str) {
        case "/yxzh/active_port/get_active_info":
            //ErlArray eaa = (message.getValue ("sid") as ErlType).getValueString ();
            String strValus = (message.getValue ("sid") as ErlType).getValueString ();
            if (strValus != null && strValus.Split(',').Length > 1) {
                strValus = ConfigHelper.GetAppConfig (message.Cmd);
            } else {
                strValus = (message.getValue ("sid") as ErlType).getValueString ();
                strValus = ConfigHelper.GetAppConfig(message.Cmd + "_" + strValus);
            }
            if (this.erlConnect != null) {
                // /yxzh/title/get_title 返回值

                ErlKVMessage msg = new ErlKVMessage ("r_ok");
                msg.addValue (null, new ErlInt (message.getPort ()));
                //String strValue = ConfigHelper.GetAppConfig (message.Cmd);
                ErlType[] et = StringKit.strToErlTypeArray (strValus);
                ErlArray ea = new ErlArray (et);
                msg.addValue ("msg", ea);
                base.send (this.erlConnect, msg);

            }
            break;
        case "/yxzh/active_port/get_text_notice":
        default:
            if (this.erlConnect != null) {
                // /yxzh/title/get_title 返回值

                ErlKVMessage msg = new ErlKVMessage ("r_ok");
                msg.addValue (null, new ErlInt (message.getPort ()));
                String strValue = ConfigHelper.GetAppConfig (message.Cmd);
                ErlType[] et = StringKit.strToErlTypeArray (strValue);
                ErlArray ea = new ErlArray (et);
                msg.addValue ("msg", ea);
                base.send (this.erlConnect, msg);
                Log.Debug (msg.toJsonString ());

            }
            break;
        }
    }
Example #5
0
    public override void read(ErlKVMessage message)
    {
        if (this.erlConnect != null) {
            ErlKVMessage msg = new ErlKVMessage ("r_ok");
            msg.addValue (null, new ErlInt (message.getPort ()));
            msg.addValue ("msg", new ErlAtom ("error"));

            base.send (this.erlConnect, msg);

        }
    }
Example #6
0
    public override void read(ErlKVMessage message)
    {
        if (this.erlConnect != null) {
            //user 返回值
            String strValue = ConfigHelper.GetAppConfig (message.Cmd);
            ErlKVMessage msg = new ErlKVMessage ("r_ok");
            msg.addValue (null, new ErlInt (message.getPort ()));
            ErlType[] et = StringKit.strToErlTypeArray (strValue);
            ErlArray ea = new ErlArray (et);
            msg.addValue ("msg", ea);
            base.send (this.erlConnect, msg);

        }
    }
    public override void erlReceive(Connect connect, ErlKVMessage message)
    {
        //this.readMessage (message);
        //Log.Info ("+++++111111111---222222222" + this.isSend + "+++++++++++");
        /*if (messagePort!=0&& messagePort == message.getPort()) {
            String strValue = ConfigHelper.GetAppConfig ("/yxzh/role/get_user");
            ErlKVMessage msg = new ErlKVMessage ("r_ok");
            msg.addValue (null, new ErlInt (messagePort));
            ErlType[] et = StringKit.strToErlTypeArray (strValue);
            ErlArray ea = new ErlArray (et);
            msg.addValue ("msg", ea);
            base.send (this.erlConnect, msg);
            if (this.erlConnect.dataBuffer.bytesAvailable > 0) {
                byte[] bts = new byte[this.erlConnect.dataBuffer.bytesAvailable];
                this.dataBuffer.readBytes (bts, 0, (int)this.erlConnect.dataBuffer.bytesAvailable);
                this.erlConnect.socket.Send (bts);
                this.dataBuffer = new ByteBuffer (bts);
            }
            isSend = true;
        }
        */
        FilterCmdManager.Instance.procPort (message.Cmd, message.getPort ());
        /*(if (message.Cmd == "/yxzh/miai_port/get_info") {
            messagePort = message.getPort();
            needProcPortDict.Add (message.getPort(), message.Cmd);
        }
        */
        Log.Info(message.Cmd+"|"+ message.toJsonString());
        //if (!isSend && this.erlConnect.transCallBack != null) {
            //this.erlConnect.transCallBack.Invoke ();

        int len = (int)this.dataBuffer.bytesAvailable;
        int pos = this.dataBuffer.position;

        byte[] tmp = new byte[len];
        byte[] bak = new byte[pos];

        this.dataBuffer.position = 0;
        this.dataBuffer.readBytes (bak, 0, pos);
        this.dataBuffer.readBytes (tmp, 0, len);
        this.dataBuffer.clear ();
        this.dataBuffer = new ByteBuffer (tmp);

        Log.Debug ("ConnectCount.getInstance().number=" + ConnectCount.getInstance ().number);
        //base.erlConnect.socket.Send (bak);

        if (this.dataBuffer.bytesAvailable > 0) {
            this.receive (null, this.isServer);
        }
    }
Example #8
0
    public void access(ErlConnect connect, ErlKVMessage message, ReceiveFun receiveFun, List <object> argus, long timeOut)
    {
        ByteBuffer data = new ByteBuffer();

        message.bytesWrite(data);
        _list.Add(new ErlEntry(connect, message.getPort(), receiveFun, argus, timeOut + TimeKit.getMillisTime()));
        connect.sendErl(data, ErlConnect.ENCRYPTION, ErlConnect.CRC, ErlConnect.COMPRESS, ErlConnect.KV);
        if (timeout == null)
        {
            timeout = TimerManager.Instance.getTimer(DELAY);
            timeout.addOnTimer(onTimer);
            timeout.start();
        }
    }
Example #9
0
    public override void read(ErlKVMessage message)
    {
        if (this.erlConnect != null) {
            string stype = (message.getValue ("type") as ErlString).Value;
            ErlKVMessage msg = new ErlKVMessage ("r_ok");
            msg.addValue (null, new ErlInt (message.getPort ()));
            String strValue = ConfigHelper.GetAppConfig (message.Cmd +"_" + stype);
            ErlType[] et = StringKit.strToErlTypeArray (strValue);
            ErlArray ub = new ErlArray (et);
            msg.addValue ("msg", ub);
            base.send (this.erlConnect, msg);

        }
    }
Example #10
0
    public override void read(ErlKVMessage message)
    {
        if (this.erlConnect != null) {
            ErlKVMessage msg = new ErlKVMessage ("r_ok");
            msg.addValue (null, new ErlInt (message.getPort ()));
            //"sids":[],"number":0,"buy":0,"act_free":0,type:502,"pstep":41
            msg.addValue ("sids", new ErlArray (new ErlType[0]));
            msg.addValue ("number", new ErlInt (0));
            msg.addValue ("buy", new ErlInt (0));
            msg.addValue ("act_free", new ErlInt (0));
            msg.addValue ("type", new ErlInt (502));
            msg.addValue ("pstep", new ErlInt (41));

            base.send (this.erlConnect, msg);

        }
    }
Example #11
0
    public override void erlReceive(Connect connect, ErlKVMessage message)
    {
        //this.readMessage (message);
        //Log.Info ("+++++111111111---222222222" + this.isSend + "+++++++++++");
        /*if (messagePort!=0&& messagePort == message.getPort()) {
            String strValue = ConfigHelper.GetAppConfig ("/yxzh/role/get_user");
            ErlKVMessage msg = new ErlKVMessage ("r_ok");
            msg.addValue (null, new ErlInt (messagePort));
            ErlType[] et = StringKit.strToErlTypeArray (strValue);
            ErlArray ea = new ErlArray (et);
            msg.addValue ("msg", ea);
            base.send (this.erlConnect, msg);
            if (this.erlConnect.dataBuffer.bytesAvailable > 0) {
                byte[] bts = new byte[this.erlConnect.dataBuffer.bytesAvailable];
                this.dataBuffer.readBytes (bts, 0, (int)this.erlConnect.dataBuffer.bytesAvailable);
                this.erlConnect.socket.Send (bts);
                this.dataBuffer = new ByteBuffer (bts);
            }
            isSend = true;
        }*/
        if (message.Cmd == "/yxzh/role/get_user") {
            messagePort = message.getPort();
        }

        Log.Info(message.Cmd+"|"+ message.toJsonString());
        //if (!isSend && this.erlConnect.transCallBack != null) {
            //this.erlConnect.transCallBack.Invoke ();
        if (!this.isServer) {
            ByteBuffer bf = (ByteBuffer)this.erlConnect.dataBuffer.Clone ();
            int pos = bf.position;
            bf.position = 0;
            this.erlConnect.socket.Send (bf.getArray ());
        }
        //this.erlConnect.dataBuffer.position = pos;

        //}
        isSend = false;
    }
Example #12
0
 public override void read(ErlKVMessage message)
 {
     if (this.erlConnect != null) {
         //登陆成功返回值
         ErlKVMessage msg = new ErlKVMessage ("r_ok");
         msg.addValue ("msg", new ErlAtom ("login_ok"));
         msg.addValue (null, new ErlInt (message.getPort ()));
         base.send (this.erlConnect, msg);
         //guild 返回值
         String strValue = ConfigHelper.GetAppConfig ("guild");
         msg = new ErlKVMessage ("guild");
         ErlType[] et = StringKit.strToErlTypeArray (strValue);
         ErlArray ea = new ErlArray (et);
         msg.addValue ("guild_skill", ea);
         base.send (this.erlConnect, msg);
         //chat 返回值
         strValue = ConfigHelper.GetAppConfig ("chat");
         msg = new ErlKVMessage ("chat");
         et = StringKit.strToErlTypeArray (strValue);
         ea = new ErlArray (et);
         msg.addValue ("msg2", ea);
         base.send (this.erlConnect, msg);
     }
 }