Beispiel #1
0
    public override void read(ErlKVMessage message)
    {
        base.read(message);
        ErlType type = message.getValue("msg") as ErlType;

        if (type is ErlInt)
        {
            ErlInt erl = type as ErlInt;
            //int index = 0;
            int checkdPoint = StringKit.toInt(erl.getValueString());
            if (callbacks != null)
            {
                callbacks(checkdPoint);
            }
            else
            {
                MaskWindow.UnlockUI();
            }
        }
        else
        {
            MessageWindow.ShowAlert((message.getValue("msg") as ErlType).getValueString());
            MaskWindow.UnlockUI();
            if (callbacks != null)
            {
                callbacks = null;
            }
        }
    }
Beispiel #2
0
    public static ErlType natureSampleAnalyse(ByteBuffer data)
    {
        int position = data.position;
        int tag      = data.readByte();

        data.position = position;

        if (tag == ErlByte.TAG)
        {
            ErlByte erlByte = new ErlByte(0);
            erlByte.bytesRead(data);
            return(erlByte);
        }
        //		else if (tag == ErlByteArray.TAG) {
        //			ErlByteArray erlByteArray = new ErlByteArray (null);
        //			erlByteArray.bytesRead(data);
        //			return erlByteArray;
        //		}
        else if (tag == ErlInt.TAG)
        {
            ErlInt erlInt = new ErlInt(0);
            erlInt.bytesRead(data);
            return(erlInt);
        }
        else if (tag == ErlString.TAG)
        {
            ErlString erlString = new ErlString("");
            erlString.sampleBytesRead(data);
            return(erlString);
        }
        else
        {
            return(null);
        }
    }
Beispiel #3
0
 private static ErlType[] getErlArr(List <object> jsonList)
 {
     ErlType[] arr = new ErlType[jsonList.Count];
     for (int i = 0; i < jsonList.Count; i++)
     {
         List <object> data = jsonList[i] as List <object>;
         ErlType       erl  = null;
         if (data[0] as string == typeof(ErlInt).Name)
         {
             erl = new ErlInt(StringKit.toInt(data[1].ToString()));
         }
         else if (data[0] as string == typeof(ErlString).Name)
         {
             erl = new ErlString(data[1].ToString());
         }
         else if (data[0] as string == typeof(ErlByte).Name)
         {
             erl = new ErlByte(byte.Parse(data[1].ToString()));
         }
         else if (data[0] as string == typeof(ErlAtom).Name)
         {
             erl = new ErlAtom(data[1].ToString());
         }
         else if (data[0] as string == typeof(ErlNullList).Name)
         {
             erl = new ErlNullList();
         }
         else if (data[0] as string == typeof(ErlArray).Name)
         {
             erl = new ErlArray(getErlArr(data[1] as List <object>));
         }
         arr[i] = erl;
     }
     return(arr);
 }
Beispiel #4
0
 //构建合击参与者
 private ErlArray createParticipant(int[] a)
 {
     ErlType[] ts = new ErlType[a.Length];
     for (int i = 0; i < ts.Length; i++)
     {
         ts[i] = new ErlInt(a[i]);
     }
     return(Round("13", new ErlArray(ts)));
 }
Beispiel #5
0
    private ErlArray createTeamInfo(int camp, int sid, int id, string uid, int hp, int maxhp, string master, int embattle)
    {
        List <ErlType> list = new List <ErlType>();

        list.Add(new ErlInt(camp));
        list.Add(new ErlInt(sid));
        list.Add(new ErlInt(id));
        list.Add(new ErlString(uid));
        list.Add(new ErlInt(hp));
        list.Add(new ErlInt(maxhp));
        list.Add(new ErlString(master));
        list.Add(new ErlInt(embattle));

        ErlType  t   = new ErlInt(4);
        ErlArray arr = new ErlArray(list.ToArray());

        return(new ErlArray(new ErlType[] { t, arr }));
    }
Beispiel #6
0
    /** 得到通讯返回port */
    public int getPort()
    {
        ErlInt erlInt = getValue(null) as ErlInt;

        if (erlInt != null)
        {
            return(erlInt.Value);
        }

        ErlByte erlByte = getValue(null) as ErlByte;

        if (erlByte != null)
        {
            return(erlByte.Value);
        }
        //throw new IOError("port is err");

        return(0);
    }
Beispiel #7
0
 private static ErlType[] getErlArr(List<object> jsonList)
 {
     ErlType[] typeArray = new ErlType[jsonList.Count];
     for (int i = 0; i < jsonList.Count; i++)
     {
         List<object> list = jsonList[i] as List<object>;
         ErlType type = null;
         if ((list[0] as string) == typeof(ErlInt).Name)
         {
             type = new ErlInt(StringKit.toInt(list[1].ToString()));
         }
         else if ((list[0] as string) == typeof(ErlString).Name)
         {
             type = new ErlString(list[1].ToString());
         }
         else if ((list[0] as string) == typeof(ErlByte).Name)
         {
             type = new ErlByte(byte.Parse(list[1].ToString()));
         }
         else if ((list[0] as string) == typeof(ErlAtom).Name)
         {
             type = new ErlAtom(list[1].ToString());
         }
         else if ((list[0] as string) == typeof(ErlNullList).Name)
         {
             type = new ErlNullList();
         }
         else if ((list[0] as string) == typeof(ErlArray).Name)
         {
             type = new ErlArray(getErlArr(list[1] as List<object>));
         }
         typeArray[i] = type;
     }
     return typeArray;
 }
Beispiel #8
0
    /** 检查列表内的所有元素都是数字,并且在0-16#80000000范围之间,条件内的列表数据转换成字符串返回 */
    public string transNumber()
    {
        if (!isString)
        {
            return(null);
        }
        ByteBuffer byteArray = new ByteBuffer();
        ErlByte    erlByte   = null;
        ErlInt     erlInt    = null;
        string     str       = null;
        string     s         = null;

        for (int j = 0; j < _value.Length; j++)
        {
            erlByte = _value [j] as ErlByte;
            //			if (j == 0 && erlByte != null && erlByte.Value == 0) {// 如果列表第一位是0,则不执行转换为字符串的操作
            //				return null;
            //			}
            if (erlByte != null && erlByte.Value > 0)
            {
                s = checkTrans(erlByte.Value);
                if (str == null)
                {
                    str = "";
                }
                if (s != null)
                {
                    str += s;
                }
                else                    // 否则把byteArray中已写入的字节转换成字符串并连接到str中
                                        //						byteArray.clear();
                                        //						byteArray.writeByte(erlByte.value);// 不是转义数字则继续写到字节数组中
                                        //						byteArray.position=0;
                                        //						if(byteArray.bytesAvailable!=0)
                                        //						{
                                        //							str+=byteArray.readMultiByte(byteArray.bytesAvailable,"//unicode");
                                        //						}
                                        //						str+=String.fromCharCode(erlByte.Value); 暂时采用下面的写法
                {
                    str += new string (new char[] { (char)(erlByte.Value) });
                }
                continue;
            }
            else
            {
                erlInt = _value [j] as ErlInt;
                if (erlInt != null && erlInt.Value > 0 && erlInt.Value < int.MaxValue)
                {
                    s = checkTrans(erlInt.Value);
                    if (str == null)
                    {
                        str = "";
                    }
                    if (s != null)
                    {
                        str += s;
                    }
                    else
                    {
                        //						byteArray.clear();
                        //						byteArray.writeInt(erlInt.value);// 不是转义数字则继续写到字节数组中
                        //						byteArray.position=0;
                        //						if(byteArray.bytesAvailable!=0)
                        //						{
                        //							trace("字符串转换  byteArray.bytesAvailable="+byteArray.bytesAvailable);
                        //							str+=byteArray.readMultiByte(byteArray.bytesAvailable,"unicode");
                        //						}
                        //str+=String.fromCharCode(erlByte.Value); 暂时采用下面的写法
//						str += new string (new char[]{(char)(erlInt.Value)});
                        str += char.ConvertFromUtf32(erlInt.Value);
                    }
                    continue;
                }
            }
            str = null;
            return(str);
        }
        return(str);
    }
 public static ErlType simpleAnalyse(ByteBuffer data)
 {
     int position = data.position;
     int num2 = data.readByte();
     data.position = position;
     switch (num2)
     {
     case 0x61:
         {
             ErlByte num3 = new ErlByte(0);
             num3.bytesRead(data);
             return num3;
         }
     case 0x6d:
         {
             ErlByteArray array = new ErlByteArray(null);
             array.simpleBytesRead(data);
             return array;
         }
     case 0x62:
         {
             ErlInt num4 = new ErlInt(0);
             num4.bytesRead(data);
             return num4;
         }
     case 0x6b:
         {
             ErlString str = new ErlString(string.Empty);
             str.bytesRead(data);
             return str;
         }
     case 110:
         {
             ErlLong @long = new ErlLong();
             @long.bytesRead(data);
             return @long;
         }
     }
     return null;
 }
Beispiel #10
0
    public static ErlType toErlType(string strValue , string strType)
    {
        if (string.IsNullOrEmpty(strValue))
        {
            return new ErlNullList();
        }
        switch (strType) {
        case "atom":
            return new ErlAtom (strValue);
        case "string":
            return new ErlString (strValue);
        case "byte":
            return new ErlByte (toInt (strValue));
        case "int":
            return new ErlInt (toInt (strValue));
        case "double":
            return new ErlDouble (toLong(strValue));
        case "clist":
            if (strValue.Length > 0) {
                char[] c = strValue.ToCharArray ();
                ErlInt[] eb = new ErlInt[c.Length];
                for (int i = 0; i < c.Length; i++) {
                    eb [i] = new ErlInt (c [i]);
                }
                ErlList el = new ErlList (eb);
                return el;
            }
            return new ErlNullList();

        default :
            if (strType.Length>5&&strType.Substring (0, 4) == "list") {
                string tmpValue = strValue.Substring (1, strValue.Length - 2);
                string tmpType = strType.Substring (5, strType.Length - 6);
                ErlType[] list = toErlTypeArray (tmpValue,tmpType , ':');
                ErlList elist = new ErlList (list);
                return elist;
            }
            if (strType.Length>6&&strType.Substring (0, 5) == "array") {
                string tmpValue = strValue.Substring (1, strValue.Length - 2);
                string tmpType = strType.Substring (6, strType.Length - 7);
                ErlType[] list = toErlTypeArray (tmpValue,tmpType , ':');
                ErlArray elist = new ErlArray (list);
                return elist;
            }
            return new ErlNullList ();
        }
    }