Skip to content

Commit

Permalink
Merge pull request #17 from tvd12/master
Browse files Browse the repository at this point in the history
release version 1.0.6
  • Loading branch information
tvd12 authored Jul 11, 2016
2 parents 28e4d27 + 2af60a6 commit 405bb9f
Show file tree
Hide file tree
Showing 124 changed files with 2,353 additions and 429 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#Synopsis

This project support to create a server side game application more efficiently and more quickly (user smartfox server engine)
This project supports to create a server side game application more efficiently and more quickly (use smartfox server engine)

#Code Example

Expand Down Expand Up @@ -108,7 +108,7 @@ Let's say you need validate a parameter in a request from client (i.e money in "
@ResponseParam("2")
private int roomId;

public void execute(AppContext context, VideoPokerUser user) throws Exception {
public void execute(AppContext context, MyUser user) throws Exception {
if(money <= 0) {
context.command(Response.class)
.command("2").recipient(user).execute();
Expand Down Expand Up @@ -143,7 +143,7 @@ We must spend a lot of time to declare, init variables. Some time we also have t
<dependency>
<groupId>com.tvd12</groupId>
<artifactId>ezyfox-core</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.tvd12</groupId>
<artifactId>ezyfox-core</artifactId>
<version>1.0.5-SNAPSHOT</version>
<version>1.0.6-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ezyfox-core</name>
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/tvd12/ezyfox/core/annotation/AutoResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
*
*/
package com.tvd12.ezyfox.core.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author tavandung12
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE })
public @interface AutoResponse {

public String[] events() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
*
* @return true or false
*/
public boolean visible() default false;
public boolean visible() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
*
* @return visible with client or not
*/
public boolean visible() default false;
public boolean visible() default true;

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static boolean validateFirstParamType(Method method) {
private static boolean validateSecondParamType(Method method,
Class<?> userClass, List<Class<?>> gameUserClasses) {
Class<?> type = method.getParameterTypes()[1];
return (type == userClass || gameUserClasses.contains(type));
return ParserUtil.isUserAgentClass(type, userClass, gameUserClasses);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.tvd12.ezyfox.core.annotation.parser;

import static com.tvd12.ezyfox.core.annotation.parser.ParserUtil.isRoomAgentClass;
import static com.tvd12.ezyfox.core.annotation.parser.ParserUtil.isUserAgentClass;
import static com.tvd12.ezyfox.core.reflect.ReflectMethodUtil.getPublicMethodSet;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Collection;

import com.tvd12.ezyfox.core.annotation.HandleMethod;
import com.tvd12.ezyfox.core.content.AppContext;
Expand All @@ -28,8 +31,7 @@ private HandleMethodParser() {}
public static Method getServerHandleMethod(Class<?> clazz,
Class<?>... parameterTypes) {
int length = parameterTypes.length;
Method[] methods = clazz.getDeclaredMethods();
for(Method method : methods) {
for(Method method : getPublicMethodSet(clazz)) {
if(!validateMethod(method, length))
continue;
for(int i = 0 ; i < length ; i++) {
Expand Down Expand Up @@ -64,11 +66,10 @@ private static boolean validateMethod(Method method, int numberOfParams) {
* @return handling method
*/
public static Method getServerHandleMethod(Class<?> clazz,
List<Class<?>> roomClasses,
Class<?> userClass, List<Class<?>> gameUserClasses) {
Method[] methods = clazz.getDeclaredMethods();
Collection<Class<?>> roomClasses,
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
Method handleMethod = getServerHandleMethod(
Arrays.asList(methods), roomClasses, userClass, gameUserClasses);
getPublicMethodSet(clazz), roomClasses, userClass, gameUserClasses);
if(handleMethod != null)
return handleMethod;
throw new RuntimeException("Has no handle methods on class " + clazz);
Expand All @@ -84,9 +85,10 @@ public static Method getServerHandleMethod(Class<?> clazz,
* @param gameUserClasses list of game user agent classes
* @return handling method
*/
private static Method getServerHandleMethod(List<Method> methods,
List<Class<?>> roomClasses,
Class<?> userClass, List<Class<?>> gameUserClasses) {
private static Method getServerHandleMethod(
Collection<Method> methods,
Collection<Class<?>> roomClasses,
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
for(Method method : methods) {
if(validateMethod(method)
&& method.getParameterTypes().length == 3
Expand Down Expand Up @@ -127,8 +129,8 @@ private static boolean validateFirstParamType(Method method) {
* @param roomClasses list of room agent classes
* @return true or false
*/
private static boolean validateSecondParamType(Method method, List<Class<?>> roomClasses) {
return roomClasses.contains(method.getParameterTypes()[1]);
private static boolean validateSecondParamType(Method method, Collection<Class<?>> roomClasses) {
return isRoomAgentClass(roomClasses, method.getParameterTypes()[1]);
}

/**
Expand All @@ -140,9 +142,9 @@ private static boolean validateSecondParamType(Method method, List<Class<?>> roo
* @return true or false
*/
private static boolean validateThirdParamType(Method method,
Class<?> userClass, List<Class<?>> gameUserClasses) {
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
Class<?> type = method.getParameterTypes()[2];
return (type == userClass || gameUserClasses.contains(type));
return isUserAgentClass(type, userClass, gameUserClasses);
}

/**
Expand All @@ -156,10 +158,9 @@ private static boolean validateThirdParamType(Method method,
*/
public static Method getServerHandleMethod(Class<?> clazz,
Class<?> modelClass,
Class<?> userClass, List<Class<?>> gameUserClasses) {
Method[] methods = clazz.getDeclaredMethods();
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
Method handleMethod = getServerHandleMethod(
Arrays.asList(methods), modelClass, userClass, gameUserClasses);
getPublicMethodSet(clazz), modelClass, userClass, gameUserClasses);
if(handleMethod != null)
return handleMethod;
throw new RuntimeException("Has no handle methods on class " + clazz);
Expand All @@ -175,9 +176,9 @@ public static Method getServerHandleMethod(Class<?> clazz,
* @param gameUserClasses game user agent's class
* @return handle method
*/
private static Method getServerHandleMethod(List<Method> methods,
private static Method getServerHandleMethod(Collection<Method> methods,
Class<?> modelClass,
Class<?> userClass, List<Class<?>> gameUserClasses) {
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
for(Method method : methods) {
if(validateMethod(method)
&& method.getParameterTypes().length == 3
Expand Down Expand Up @@ -210,10 +211,9 @@ private static boolean validateSecondParamType(Method method, Class<?> modelClas
* @return handling method
*/
public static Method getServerHandleMethod(Class<?> clazz,
Class<?> userClass, List<Class<?>> gameUserClasses) {
Method[] methods = clazz.getDeclaredMethods();
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
Method handleMethod = getServerHandleMethod(
Arrays.asList(methods), userClass, gameUserClasses);
getPublicMethodSet(clazz), userClass, gameUserClasses);
if(handleMethod != null)
return handleMethod;
throw new RuntimeException("Has no handle methods on class " + clazz);
Expand All @@ -228,8 +228,8 @@ public static Method getServerHandleMethod(Class<?> clazz,
* @param gameUserClasses list of game user agent classes
* @return handling method
*/
private static Method getServerHandleMethod(List<Method> methods,
Class<?> userClass, List<Class<?>> gameUserClasses) {
private static Method getServerHandleMethod(Collection<Method> methods,
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
for(Method method : methods) {
if(validateMethod(method)
&& method.getParameterTypes().length == 2
Expand All @@ -250,8 +250,8 @@ && validateSecondParamType(method, userClass, gameUserClasses)) {
* @return true or false
*/
private static boolean validateSecondParamType(Method method,
Class<?> userClass, List<Class<?>> gameUserClasses) {
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
Class<?> type = method.getParameterTypes()[1];
return (type == userClass || gameUserClasses.contains(type));
return isUserAgentClass(type, userClass, gameUserClasses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
*
*/
package com.tvd12.ezyfox.core.annotation.parser;

import java.util.Collection;

import com.tvd12.ezyfox.core.entities.ApiRoom;
import com.tvd12.ezyfox.core.entities.ApiUser;

/**
* @author tavandung12
*
*/
public class ParserUtil {

private ParserUtil() {}

public static boolean isUserAgentClass(Class<?> paramType,
Class<?> userClass, Collection<Class<?>> gameUserClasses) {
return paramType == ApiUser.class ||
paramType == userClass ||
gameUserClasses.contains(paramType);
}

public static boolean isRoomAgentClass(Collection<Class<?>> roomClasses,
Class<?> paramType) {
return paramType == ApiRoom.class || roomClasses.contains(paramType);
}
}
18 changes: 9 additions & 9 deletions src/main/java/com/tvd12/ezyfox/core/command/AddBuddy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
package com.tvd12.ezyfox.core.command;

import com.tvd12.ezyfox.core.model.ApiBaseUser;
import com.tvd12.ezyfox.core.model.ApiZone;
import com.tvd12.ezyfox.core.entities.ApiBaseUser;
import com.tvd12.ezyfox.core.entities.ApiZone;

/**
* Execute this command to adds a new buddy to the BuddyList of the specified User.
Expand All @@ -20,15 +20,15 @@ public interface AddBuddy extends BaseCommand {
* @param owner owner
* @return this pointer
*/
public <T extends AddBuddy> T owner(ApiBaseUser owner);
AddBuddy owner(ApiBaseUser owner);

/**
* name of buddy's owner
*
* @param ownerName owner name
* @return this pointer
*/
public <T extends AddBuddy> T owner(String ownerName);
AddBuddy owner(String ownerName);

/**
* If you set zone this command will add a buddy to the User's buddy list
Expand All @@ -37,38 +37,38 @@ public interface AddBuddy extends BaseCommand {
* @param zone which zone user's now in
* @return this pointer
*/
public <T extends AddBuddy> T zone(ApiZone zone);
AddBuddy zone(ApiZone zone);

/**
* name of buddy to add
*
* @param buddyName buddy name
* @return this pointer
*/
public <T extends AddBuddy> T buddy(String buddyName);
AddBuddy buddy(String buddyName);

/**
* if true, the Buddy is only temporary and will be lost when the user logs out
*
* @param isTemp is temporary?
* @return this pointer
*/
public <T extends AddBuddy> T temp(boolean isTemp);
AddBuddy temp(boolean isTemp);

/**
* if true, send a client update
*
* @param fireClientEvent if true, send a client update
* @return this pointer
*/
public <T extends AddBuddy> T fireClientEvent(boolean fireClientEvent);
AddBuddy fireClientEvent(boolean fireClientEvent);

/**
* if true, fire a server event (BUDDY_ADDED)
*
* @param fireServerEvent if true, fire a server event (BUDDY_ADDED)
* @return this pointer
*/
public <T extends AddBuddy> T fireServerEvent(boolean fireServerEvent);
AddBuddy fireServerEvent(boolean fireServerEvent);

}
18 changes: 9 additions & 9 deletions src/main/java/com/tvd12/ezyfox/core/command/BanUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package com.tvd12.ezyfox.core.command;

import com.tvd12.ezyfox.core.model.ApiBaseUser;
import com.tvd12.ezyfox.core.entities.ApiBaseUser;

/**
* Execute this command when you want to ban an user
Expand All @@ -19,59 +19,59 @@ public interface BanUser extends BaseCommand {
* @param userToBan
* @return this pointer
*/
public <T extends BanUser> T user(ApiBaseUser userToBan);
BanUser user(ApiBaseUser userToBan);

/**
* set user name of user to ban
*
* @param userToBan user name of user to ban
* @return this pointer
*/
public <T extends BanUser> T user(String userToBan);
BanUser user(String userToBan);

/**
* set the mod/admin user name, can be null to indicate generically the "Server"
*
* @param modUser mod/admin user name
* @return this pointer
*/
public <T extends BanUser> T modUser(String modUser);
BanUser modUser(String modUser);

/**
* set ban message
*
* @param banMessage ban message
* @return this pointer
*/
public <T extends BanUser> T message(String banMessage);
BanUser message(String banMessage);

/**
* choose between banning by Ip Address or by User name
*
* @return this pointer
*/
public <T extends BanUser> T byAddress();
BanUser byAddress();

/**
* choose between banning by ip address or by User name
*
* @return this pointer
*/
public <T extends BanUser> T byName();
BanUser byName();

/**
* the duration of the banishment in hours
*
* @param durationMinutes duration in minute
* @return this pointer
*/
public <T extends BanUser> T duration(int durationMinutes);
BanUser duration(int durationMinutes);

/**
* delay before the disconnection is performed
*
* @param delaySeconds delay time in second
* @return this pointer
*/
public <T extends BanUser> T delay(int delaySeconds);
BanUser delay(int delaySeconds);
}
Loading

0 comments on commit 405bb9f

Please sign in to comment.