クッキー関連
@@ -0,0 +1,25 @@ | ||
1 | +package servercore.data; | |
2 | + | |
3 | +public class Cookie { | |
4 | + private long expire = 0; | |
5 | + private String key = null; | |
6 | + private String value = null; | |
7 | + public void setExpire(long expire) { | |
8 | + this.expire = expire; | |
9 | + } | |
10 | + public long getExpire() { | |
11 | + return expire; | |
12 | + } | |
13 | + public void setKey(String key) { | |
14 | + this.key = key; | |
15 | + } | |
16 | + public String getKey() { | |
17 | + return key; | |
18 | + } | |
19 | + public void setValue(String value) { | |
20 | + this.value = value; | |
21 | + } | |
22 | + public String getValue() { | |
23 | + return value; | |
24 | + } | |
25 | +} |
@@ -0,0 +1,27 @@ | ||
1 | +package servercore.job; | |
2 | + | |
3 | +import java.util.HashMap; | |
4 | + | |
5 | +import servercore.data.Cookie; | |
6 | + | |
7 | +public class SessionCheck { | |
8 | + static private HashMap<String, Cookie> map = new HashMap<String, Cookie>(); | |
9 | + static public Cookie getCookie(String key) { | |
10 | + Cookie cookie = map.get(key); | |
11 | + if(cookie == null) { | |
12 | + return null; | |
13 | + } | |
14 | + if(cookie.getExpire() < System.currentTimeMillis()) { | |
15 | + map.put(key, null); | |
16 | + return null; | |
17 | + } | |
18 | + return cookie; | |
19 | + } | |
20 | + static public void setCookie(String key, String value, long expireTo) { | |
21 | + Cookie cookie = new Cookie(); | |
22 | + cookie.setKey(key); | |
23 | + cookie.setValue(value); | |
24 | + cookie.setExpire(System.currentTimeMillis() + expireTo * 1000); | |
25 | + map.put(key, cookie); | |
26 | + } | |
27 | +} |