Example #1
0
    public void syncPosition(long gameId,
                             string objectName,
                             int objectType,
                             int objectId,
                             bool visible,
                             double x,
                             double y,
                             double z
                             )
    {
        if (!appAccessed)
        {
            return;
        }
        var position = EzyEntityFactory.newObject();

        position.put("x", x);
        position.put("y", y);
        position.put("z", z);
        var request = EzyEntityFactory.newObject();

        request.put("gameName", GAME_NAME);
        request.put("gameId", gameId);
        request.put("objectId", objectId);
        request.put("objectName", objectName);
        request.put("objectType", objectType);
        request.put("visible", visible);
        request.put("position", position);
        var app = socketClient.getApp();

        if (app != null)
        {
            app.udpSend("syncPosition", request);
        }
    }
Example #2
0
        protected override EzyObject objectToMap(T obj, EzyMarshaller marshaller)
        {
            EzyObject map = EzyEntityFactory.newObject();

            foreach (PropertyInfo property in objectType.GetProperties())
            {
                string   key  = null;
                EzyValue anno = property.GetCustomAttribute <EzyValue>();
                if (anno != null)
                {
                    key = anno.name;
                }
                else
                {
                    key = property.Name.Length <= 1
                        ? char.ToLower(property.Name[0]).ToString()
                        : char.ToLower(property.Name[0]) + property.Name.Substring(1);
                }
                object rawValue = property.GetValue(obj);
                object value    = rawValue != null?marshaller.marshall <object>(rawValue) : null;

                map.put(key, value);
            }
            return(map);
        }
Example #3
0
    public void getGameId()
    {
        var request = EzyEntityFactory.newObject();

        request.put("gameName", GAME_NAME);
        socketClient.getApp().send("getGameId", request);
    }
        protected override EzyArray objectToArray(T obj, EzyMarshaller marshaller)
        {
            int count = 0;
            SortedDictionary <int, object> valueByIndex = new SortedDictionary <int, object>();

            foreach (PropertyInfo property in objectType.GetProperties())
            {
                EzyValue anno     = property.GetCustomAttribute <EzyValue>();
                int      index    = anno != null ? anno.index : count;
                object   rawValue = property.GetValue(obj);
                object   value    = rawValue != null?marshaller.marshall <object>(rawValue) : null;

                valueByIndex[index] = value;
                ++count;
            }
            EzyArray array = EzyEntityFactory.newArray();

            for (int i = 0; i < count; ++i)
            {
                object value = null;
                if (valueByIndex.ContainsKey(i))
                {
                    value = valueByIndex[i];
                }
                array.add(value);
            }
            return(array);
        }
Example #5
0
    protected override void postHandle(EzyApp app, EzyArray data)
    {
        var request = EzyEntityFactory.newObject();

        request.put("gameName", SocketClientProxy.GAME_NAME);
        app.send("reconnect", request);
    }
Example #6
0
        public EzyData serialize()
        {
            EzyData answer = EzyEntityFactory.newArrayBuilder()
                             .append(appId)
                             .build();

            return(answer);
        }
Example #7
0
        public void handle(EzyApp app, EzyData d)
        {
            EzyArray pos = EzyEntityFactory.newArrayBuilder()
                           .append(1.0D, 2.0D, 3.0D)
                           .build();

            app.send(Commands.SYNC_POSITION, pos);
        }
Example #8
0
    public void finishGame(long gameId)
    {
        var request = EzyEntityFactory.newObject();

        request.put("gameName", GAME_NAME);
        request.put("gameId", gameId);
        socketClient.getApp().send("finishGame", request);
    }
Example #9
0
        protected override void onAuthenticated(EzyArray data)
        {
            EzyApp app = client.getZone().getApp();

            app.udpSend("udpGreet", EzyEntityFactory.newObjectBuilder()
                        .append("who", "Dzung")
                        .build());
        }
        public virtual EzyArray serialize(EzyCommand cmd, EzyArray data)
        {
            EzyArray array = EzyEntityFactory.newArrayBuilder()
                             .append((int)cmd)
                             .append(data)
                             .build();

            return(array);
        }
Example #11
0
    public void deleteGameObject(long gameId, int objectId)
    {
        var request = EzyEntityFactory.newObject();

        request.put("gameName", GAME_NAME);
        request.put("gameId", gameId);
        request.put("objectId", objectId);
        socketClient.getApp().send("deleteGameObject", request);
    }
Example #12
0
    public void syncScore(long gameId, long score)
    {
        var request = EzyEntityFactory.newObject();

        request.put("gameName", GAME_NAME);
        request.put("gameId", gameId);
        request.put("score", score);
        socketClient.getApp().send("updateScore", request);
    }
Example #13
0
        public EzyData serialize()
        {
            EzyData answer = EzyEntityFactory.newArrayBuilder()
                             .append(zoneName)
                             .append(username)
                             .append(password)
                             .append(data).build();

            return(answer);
        }
    public void SendPluginInfoRequest(string pluginName)
    {
        var client = SocketProxy.getInstance().Client;

        var request = EzyEntityFactory.newArrayBuilder()
                      .append(pluginName)
                      .build();

        client.send(EzyCommand.PLUGIN_INFO, request);
    }
Example #15
0
 protected override EzyRequest getLoginRequest()
 {
     return(new EzyLoginRequest(
                SocketClientProxy.ZONE_NAME,
                SocketClientProxy.getInstance().username,
                SocketClientProxy.getInstance().password,
                EzyEntityFactory.newArrayBuilder()
                .append("gameName", SocketClientProxy.GAME_NAME)
                .build()
                ));
 }
        public void udpSend(String cmd, EzyData data)
        {
            EzyArrayBuilder commandData = EzyEntityFactory.newArrayBuilder()
                                          .append(cmd)
                                          .append(data);
            EzyArray requestData = EzyEntityFactory.newArrayBuilder()
                                   .append(id)
                                   .append(commandData.build())
                                   .build();

            client.udpSend(EzyCommand.PLUGIN_REQUEST, requestData);
        }
        public EzyData serialize()
        {
            EzyData data = EzyEntityFactory.newArrayBuilder()
                           .append(clientId)
                           .append(clientKey)
                           .append(clientType)
                           .append(clientVersion)
                           .append(enableEncryption)
                           .append(token).build();

            return(data);
        }
Example #18
0
        public object read(object input, EzyUnmarshaller unmarshaller)
        {
            EzyArray array = null;

            if (input is IList)
            {
                array = EzyEntityFactory.newArrayBuilder()
                        .appendRawList((IList)input)
                        .build();
            }
            else
            {
                array = (EzyArray)input;
            }
            return(arrayToObject(array, unmarshaller));
        }
Example #19
0
        public object read(object input, EzyUnmarshaller unmarshaller)
        {
            EzyObject map = null;

            if (input is IDictionary)
            {
                map = EzyEntityFactory.newObjectBuilder()
                      .appendRawDict((IDictionary)input)
                      .build();
            }
            else
            {
                map = (EzyObject)input;
            }
            return(mapToObject(map, unmarshaller));
        }
Example #20
0
 public object marshallByInType(object input, Type inType)
 {
     if (input == null)
     {
         return(null);
     }
     if (writerByInType.ContainsKey(inType))
     {
         IEzyWriter writer = writerByInType[inType];
         return(writer.write(input, this));
     }
     if (typeof(IDictionary).IsAssignableFrom(inType))
     {
         EzyObject   answer    = EzyEntityFactory.newObject();
         IDictionary dict      = (IDictionary)(input);
         Type        keyType   = inType.GetGenericArguments()[0];
         Type        valueType = inType.GetGenericArguments()[1];
         foreach (DictionaryEntry entry in dict)
         {
             answer.put(
                 marshallByInType(entry.Key, keyType),
                 marshallByInType(entry.Value, valueType));
         }
         return(answer);
     }
     else if (typeof(IList).IsAssignableFrom(inType))
     {
         EzyArray answer    = EzyEntityFactory.newArray();
         IList    list      = (IList)(input);
         Type     valueType = inType.GetGenericArguments()[0];
         foreach (Object value in list)
         {
             answer.add(marshallByInType(value, valueType));
         }
         return(answer);
     }
     return(input);
 }
Example #21
0
 protected Object transformNonNullValue(Object value)
 {
     if (value is IDictionary)
     {
         IDictionary dictionary = (IDictionary)value;
         EzyObject   obj        = EzyEntityFactory.newObject();
         foreach (DictionaryEntry entry in dictionary)
         {
             obj.put(transform(entry.Key), transform(entry.Value));
         }
         return(obj);
     }
     if (value is ICollection)
     {
         IEnumerable collection = (IEnumerable)value;
         EzyArray    array      = EzyEntityFactory.newArray();
         foreach (Object item in collection)
         {
             array.add(transform(item));
         }
         return(array);
     }
     return(value);
 }
Example #22
0
 private static EzyObjectBuilder newObjectBuilder()
 {
     return(EzyEntityFactory.newObjectBuilder());
 }
Example #23
0
 private static EzyArrayBuilder newArrayBuilder()
 {
     return(EzyEntityFactory.newArrayBuilder());
 }
 protected EzyObjectBuilder newObjectBuilder()
 {
     return(EzyEntityFactory.newObjectBuilder());
 }
 protected EzyArrayBuilder newArrayBuilder()
 {
     return(EzyEntityFactory.newArrayBuilder());
 }
Example #26
0
        public void Run()
        {
            IDictionary <String, Double> dict1 = new Dictionary <String, Double>();

            dict1["a"]      = 1.0D;
            dict1["b"]      = 2.0F;
            dict1["sbyte"]  = (sbyte)100;
            dict1["byte"]   = (byte)101;
            dict1["double"] = (double)102.3D;
            dict1["float"]  = (float)103.4F;
            dict1["int"]    = (int)104;
            dict1["long"]   = (long)105;
            dict1["short"]  = (short)106;

            IList <Object> list1 = new List <Object>();

            list1.Add(dict1);
            list1.Add((Int64)100);

            IDictionary <Object, Object> dict2 = new Dictionary <Object, Object>();

            dict2[list1]   = dict1;
            dict2["Hello"] = "World";
            dict2["c"]     = 3.0D;
            dict2[dict1]   = list1;

            List <Object> list2 = new List <object>();

            list2.Add(dict1);
            list2.Add(dict2);
            list2.Add(list1);

            EzyArray array = EzyEntityFactory.newArrayBuilder()
                             .append(dict1)
                             .append(dict2)
                             .append(list1)
                             .appendAll(list2)
                             .build();
            EzyObject obj = EzyEntityFactory.newObjectBuilder()
                            .append(dict1)
                            .append(dict2)
                            .append("list1", list1)
                            .append("list2", list2)
                            .build();

            int expectedListCount = 1 + 1 + 1 + list2.Count;

            if (array.size() != expectedListCount)
            {
                throw new ArgumentException("expected: " + expectedListCount + " but: " + array.size());
            }

            int expectedDictCount = dict1.Count + dict2.Count + 1 + 1;

            if (obj.size() != expectedDictCount)
            {
                throw new ArgumentException("expected: " + expectedDictCount + " but: " + array.size());
            }
            Console.WriteLine("array: " + array);
            Console.WriteLine("\n\nobj: " + obj);

            Console.WriteLine("\n\nclone array: " + array.Clone());
            Console.WriteLine("\n\nclone obj: " + obj.Clone());

            Console.WriteLine("\n\nlong from double" + obj.get <long>("a"));

            Console.WriteLine("sbyte from sbyte: " + obj.get <sbyte>("sbyte"));
            Console.WriteLine("byte from sbyte: " + obj.get <byte>("sbyte"));
            Console.WriteLine("double from sbyte: " + obj.get <double>("sbyte"));
            Console.WriteLine("float from sbyte: " + obj.get <float>("sbyte"));
            Console.WriteLine("int from sbyte: " + obj.get <int>("sbyte"));
            Console.WriteLine("long from sbyte: " + obj.get <long>("sbyte"));
            Console.WriteLine("short from sbyte: " + obj.get <short>("sbyte"));

            Console.WriteLine("sbyte from byte: " + obj.get <sbyte>("byte"));
            Console.WriteLine("byte from byte: " + obj.get <byte>("byte"));
            Console.WriteLine("double from byte: " + obj.get <double>("byte"));
            Console.WriteLine("float from byte: " + obj.get <float>("byte"));
            Console.WriteLine("int from byte: " + obj.get <int>("byte"));
            Console.WriteLine("long from byte: " + obj.get <long>("byte"));
            Console.WriteLine("short from byte: " + obj.get <short>("byte"));

            Console.WriteLine("sbyte from double: " + obj.get <double>("double"));
            Console.WriteLine("byte from double: " + obj.get <byte>("double"));
            Console.WriteLine("double from double: " + obj.get <double>("double"));
            Console.WriteLine("float from double: " + obj.get <float>("double"));
            Console.WriteLine("int from double: " + obj.get <int>("double"));
            Console.WriteLine("long from double: " + obj.get <long>("double"));
            Console.WriteLine("short from double: " + obj.get <short>("double"));

            Console.WriteLine("sbyte from float: " + obj.get <float>("float"));
            Console.WriteLine("byte from float: " + obj.get <byte>("float"));
            Console.WriteLine("double from float: " + obj.get <double>("float"));
            Console.WriteLine("float from float: " + obj.get <float>("float"));
            Console.WriteLine("int from float: " + obj.get <int>("float"));
            Console.WriteLine("long from float: " + obj.get <long>("float"));
            Console.WriteLine("short from float: " + obj.get <short>("float"));

            Console.WriteLine("sbyte from int: " + obj.get <int>("int"));
            Console.WriteLine("byte from int: " + obj.get <byte>("int"));
            Console.WriteLine("double from int: " + obj.get <double>("int"));
            Console.WriteLine("float from int: " + obj.get <float>("int"));
            Console.WriteLine("int from int: " + obj.get <int>("int"));
            Console.WriteLine("long from int: " + obj.get <long>("int"));
            Console.WriteLine("short from int: " + obj.get <short>("int"));

            Console.WriteLine("sbyte from long: " + obj.get <long>("long"));
            Console.WriteLine("byte from long: " + obj.get <byte>("long"));
            Console.WriteLine("double from long: " + obj.get <double>("long"));
            Console.WriteLine("float from long: " + obj.get <float>("long"));
            Console.WriteLine("int from long: " + obj.get <int>("long"));
            Console.WriteLine("long from long: " + obj.get <long>("long"));
            Console.WriteLine("short from long: " + obj.get <short>("long"));

            Console.WriteLine("sbyte from short: " + obj.get <short>("short"));
            Console.WriteLine("byte from short: " + obj.get <byte>("short"));
            Console.WriteLine("double from short: " + obj.get <double>("short"));
            Console.WriteLine("float from short: " + obj.get <float>("short"));
            Console.WriteLine("int from short: " + obj.get <int>("short"));
            Console.WriteLine("long from short: " + obj.get <long>("short"));
            Console.WriteLine("short from short: " + obj.get <short>("short"));

            List <object> l = array.toList <object>();
            IDictionary <object, object> d = obj.toDict <object, object>();

            if (l.Count != expectedListCount)
            {
                throw new ArgumentException("expected: " + expectedListCount + " but: " + l.Count);
            }
            if (d.Count != expectedDictCount)
            {
                throw new ArgumentException("expected: " + expectedDictCount + " but: " + d.Count);
            }

            Console.WriteLine("list: " + l);
            Console.WriteLine("dict: " + d);
        }