public override void handle(EzyArray data) { preHandle(data); pingSchedule.start(); handleLogin(data); postHandle(data); }
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); }
public override void handle(EzyArray data) { int appId = data.get <int>(0); EzyArray commandData = data.get <EzyArray>(1); String cmd = commandData.get <String>(0); EzyData responseData = commandData.get <EzyData>(1, null); EzyApp app = client.getAppById(appId); if (app == null) { logger.info("receive message when has not joined app yet"); return; } EzyAppDataHandler dataHandler = app.getDataHandler(cmd); if (dataHandler != null) { dataHandler.handle(app, responseData); } else { logger.warn("app: " + app.getName() + " has no handler for command: " + cmd); } }
protected void printSentData(EzyCommand cmd, EzyArray data) { if (!unloggableCommands.Contains(cmd)) { logger.debug("send command: " + cmd + " and data: " + data); } }
protected override void postHandle(EzyApp app, EzyArray data) { var request = EzyEntityFactory.newObject(); request.put("gameName", SocketClientProxy.GAME_NAME); app.send("reconnect", request); }
public override void handle(EzyArray data) { int pluginId = data.get <int>(0); EzyArray commandData = data.get <EzyArray>(1); String cmd = commandData.get <String>(0); EzyData responseData = commandData.get <EzyData>(1, null); EzyPlugin plugin = client.getPluginById(pluginId); if (plugin == null) { logger.info("receive message when has not joined plugin yet"); return; } EzyPluginDataHandler dataHandler = plugin.getDataHandler(cmd); if (dataHandler != null) { dataHandler.handle(plugin, responseData); } else { logger.warn("plugin: " + plugin.getName() + " has no handler for command: " + cmd); } }
public EzySimpleResponse(EzyArray data) { this.data = data; int cmdId = data.get <int>(0); this.command = (EzyCommand)cmdId; this.timestamp = DateTime.Now; }
protected virtual EzyUser newUser(EzyArray data) { long userId = data.get <long>(2); String username = data.get <String>(3); EzySimpleUser user = new EzySimpleUser(userId, username); return(user); }
protected virtual EzyApp newApp(EzyZone zone, EzyArray data) { int appId = data.get <int>(0); String appName = data.get <String>(1); EzySimpleApp app = new EzySimpleApp(zone, appId, appName); return(app); }
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); }
protected virtual EzyZone newZone(EzyArray data) { int zoneId = data.get <int>(0); String zoneName = data.get <String>(1); EzySimpleZone zone = new EzySimpleZone(client, zoneId, zoneName); return(zone); }
protected override void onAuthenticated(EzyArray data) { EzyApp app = client.getZone().getApp(); app.udpSend("udpGreet", EzyEntityFactory.newObjectBuilder() .append("who", "Dzung") .build()); }
protected virtual EzyPlugin newPlugin(EzyZone zone, EzyArray data) { int pluginId = data.get <int>(0); String pluginName = data.get <String>(1); EzySimplePlugin plugin = new EzySimplePlugin(zone, pluginId, pluginName); return(plugin); }
public virtual EzyArray serialize(EzyCommand cmd, EzyArray data) { EzyArray array = EzyEntityFactory.newArrayBuilder() .append((int)cmd) .append(data) .build(); return(array); }
protected override void process() { EzyArray data = ticketsQueue.take(); getLogger().debug("send: {0}", data); Object bytes = encodeData(data); writeBytes(bytes); }
public override void udpSend(EzyCommand cmd, EzyArray data) { EzyArray array = requestSerializer.serialize(cmd, data); if (socketClient != null) { ((EzyUTSocketClient)socketClient).udpSendMessage(array); printSentData(cmd, data); } }
public void send(EzyCommand cmd, EzyArray data) { EzyArray array = requestSerializer.serialize(cmd, data); if (socketClient != null) { socketClient.sendMessage(array); printSentData(cmd, data); } }
public override void handle(EzyArray data) { EzyZone zone = client.getZone(); EzyPluginManager pluginManager = zone.getPluginManager(); EzyPlugin plugin = newPlugin(zone, data); pluginManager.addPlugin(plugin); postHandle(plugin, data); logger.info("access plugin: " + plugin.getName() + " successfully"); }
public IList <T> unmarshallList <T>(EzyArray array) { List <T> answer = new List <T>(); for (int i = 0; i < array.size(); ++i) { answer.Add(unmarshall <T>(array.get <object>(i))); } return(answer); }
public override void handle(EzyArray data) { EzyZone zone = client.getZone(); EzyAppManager appManager = zone.getAppManager(); EzyApp app = newApp(zone, data); appManager.addApp(app); postHandle(app, data); logger.info("access app: " + app.getName() + " successfully"); }
public override void handle(EzyArray data) { EzyData responseData = data.get <EzyData>(4); EzyUser user = newUser(data); EzyZone zone = newZone(data); ((EzyMeAware)client).setMe(user); ((EzyZoneAware)client).setZone(zone); handleLoginSuccess(responseData); logger.debug("user: "******" logged in successfully"); }
protected override T arrayToObject(EzyArray array, EzyUnmarshaller unmarshaller) { T obj = (T)Activator.CreateInstance(objectType); PropertyInfo[] properties = objectType.GetProperties(); for (int i = 0; i < properties.Length; ++i) { PropertyInfo targetProperty = properties[i]; EzyValue anno = targetProperty.GetCustomAttribute <EzyValue>(); int index = anno != null ? anno.index : i; if (index >= array.size()) { continue; } Type outType = targetProperty.PropertyType; object rawValue = array.getByOutType(index, outType); if (rawValue == null) { continue; } object value = unmarshaller.unmarshallByOutType(rawValue, outType); if (targetProperty.PropertyType == value.GetType()) { targetProperty.SetValue(obj, value); } else { MethodInfo parseMethod = targetProperty.PropertyType.GetMethod( "TryParse", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(string), targetProperty.PropertyType.MakeByRefType() }, null ); if (parseMethod != null) { object[] parameters = new[] { value, null }; bool success = (bool)parseMethod.Invoke(null, parameters); if (success) { targetProperty.SetValue(obj, parameters[1]); } } } } return(obj); }
public void handle(EzyCommand cmd, EzyArray data) { if (handlers.ContainsKey(cmd)) { EzyDataHandler hd = handlers[cmd]; hd.handle(data); } else { logger.warn("has no handler for command: " + cmd); } }
public void sendMessage(EzyArray message) { EzyPackage pack = new EzySimplePackage(message, EzyTransportType.UDP); try { responseApi.response(pack); } catch (Exception e) { logger.warn("udp send message: " + message + " error", e); } }
protected byte[] parseArray(EzyArray array) { int index = 1; int size = array.size(); byte[][] bytess = new byte[size + 1][]; bytess[0] = parseArraySize(size); for (int i = 0; i < size; i++) { bytess[index++] = serialize(array.get <Object>(i)); } return(EzyBytes.merge(bytess)); }
public override void handle(EzyArray data) { EzyZone zone = client.getZone(); EzyAppManager appManager = zone.getAppManager(); int appId = data.get <int>(0); int reasonId = data.get <int>(1); EzyApp app = appManager.removeApp(appId); if (app != null) { postHandle(app, data); logger.info("user exit app: " + app + ", reason: " + reasonId); } }
public object unmarshallByOutType(object input, Type outType) { if (input == null) { return(null); } if (readerByOutType.ContainsKey(outType)) { IEzyReader reader = readerByOutType[outType]; return(reader.read(input, this)); } if (outType.IsGenericType) { if (typeof(IDictionary).IsAssignableFrom(outType) || typeof(IDictionary <,>) == outType.GetGenericTypeDefinition()) { Type dictType = typeof(Dictionary <,>); Type constructed = dictType.MakeGenericType(outType.GetGenericArguments()); IDictionary answer = (IDictionary)Activator.CreateInstance(constructed); EzyObject obj = (EzyObject)input; Type keyType = outType.GetGenericArguments()[0]; Type valueType = outType.GetGenericArguments()[1]; foreach (object key in obj.keys()) { answer[unmarshallByOutType(key, keyType)] = unmarshallByOutType(obj.getByOutType(key, valueType), valueType); } return(answer); } else if (typeof(IList).IsAssignableFrom(outType) || typeof(IList <>) == outType.GetGenericTypeDefinition()) { Type listType = typeof(List <>); Type constructed = listType.MakeGenericType(outType.GetGenericArguments()); IList answer = (IList)Activator.CreateInstance(constructed); EzyArray array = (EzyArray)input; Type valueType = outType.GetGenericArguments()[0]; for (int i = 0; i < array.size(); ++i) { Object rawValue = array.getByOutType(i, valueType); Object value = unmarshallByOutType(rawValue, valueType); answer.Add(value); } return(answer); } } return(input); }
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)); }
protected void processReceivedMessage(EzyArray message) { int cmdId = message.get <int>(0); EzyArray data = message.get <EzyArray>(1, null); EzyCommand cmd = (EzyCommand)cmdId; printReceivedData(cmd, data); if (cmd == EzyCommand.DISCONNECT) { int reasonId = data.get <int>(0); disconnectReason = reasonId; socketStatuses.push(EzySocketStatus.DISCONNECTING); } else { dataHandlers.handle(cmd, data); } }
public override void handle(EzyArray data) { int responseCode = data.get <int>(0); EzyUTClient utClient = (EzyUTClient)client; EzyUTSocketClient socket = (EzyUTSocketClient)client.getSocket(); if (responseCode == EzyStatusCodes.OK) { utClient.setUdpStatus(EzyConnectionStatus.CONNECTED); socket.udpSetStatus(EzySocketStatus.CONNECTED); onAuthenticated(data); } else { utClient.setUdpStatus(EzyConnectionStatus.FAILURE); socket.udpSetStatus(EzySocketStatus.CONNECT_FAILED); onAuthenticationError(data); } }