├── .classpath
├── .gitattributes
├── .gitignore
├── .project
├── README.md
└── src
└── com
└── brekcel
└── csgostate
├── Info.java
├── JSON
├── Added.java
├── Auth.java
├── JsonResponse.java
├── Map.java
├── MatchStats.java
├── Player.java
├── Previously.java
├── Provider.java
├── Round.java
├── State.java
├── Team.java
└── Weapon.java
├── Server.java
└── post
├── PostHandler.java
├── PostHandlerAdapter.java
└── PostReceiver.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
14 | # =========================
15 | # Operating System Files
16 | # =========================
17 |
18 | # OSX
19 | # =========================
20 |
21 | .DS_Store
22 | .AppleDouble
23 | .LSOverride
24 |
25 | # Thumbnails
26 | ._*
27 |
28 | # Files that might appear in the root of a volume
29 | .DocumentRevisions-V100
30 | .fseventsd
31 | .Spotlight-V100
32 | .TemporaryItems
33 | .Trashes
34 | .VolumeIcon.icns
35 |
36 | # Directories potentially created on remote AFP share
37 | .AppleDB
38 | .AppleDesktop
39 | Network Trash Folder
40 | Temporary Items
41 | .apdisk
42 |
43 | # Windows
44 | # =========================
45 |
46 | # Windows image file caches
47 | Thumbs.db
48 | ehthumbs.db
49 |
50 | # Folder config file
51 | Desktop.ini
52 |
53 | # Recycle Bin used on file shares
54 | $RECYCLE.BIN/
55 |
56 | # Windows Installer files
57 | *.cab
58 | *.msi
59 | *.msm
60 | *.msp
61 |
62 | # Windows shortcuts
63 | *.lnk
64 |
65 | # CSGOState ignores
66 | src/com/google/
67 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | CSGOState
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CSGOState
2 | Java library for Counter-Strike: Global Offensive's Game State Integration.
3 |
4 | Still in very early development.
5 |
6 | Majority of development is streamed live on [Twitch](http://www.twitch.tv/sakki54)
7 |
8 | ## Dependencies
9 | * [Google's Gson](https://github.com/google/gson)
10 |
11 | ## Progress
12 | Finished:
13 | * All methods in PostHandler Interface EXCEPT for the Weapon methods.
14 |
15 | In-Progress:
16 | * Weapon handling rework.
17 | * Documentation writing.
18 | * Inevitable Bug Fixes.
19 |
20 | ## Usage
21 | To start the server:
22 |
23 | ```java
24 | new Server(int port, PostHandler postHandle, boolean OnlyUserInfo, String authToken);
25 | ```
26 |
27 | Or
28 |
29 | ```java
30 | new Server(int port, PostHandler postHandle, boolean OnlyUserInfo);
31 | ```
32 |
33 | For Example:
34 |
35 | ```java
36 | new Server(1338, PostHandler, true, "supersecretpassword");
37 | ```
38 |
39 | The PostHandler class is a new class that either implements PostHandler to override all possible methods called, or extends PostHandlerAdapter in order to only override the necessary methods needed from the PostHandler class.
40 |
41 | For Example:
42 |
43 | ```java
44 | import com.brekcel.csgostate.post.PostHandlerAdapter;
45 |
46 | public class PostOverride extends PostHandlerAdapter {
47 |
48 | @Override
49 | public void playerHealthChange(int health) {
50 | System.out.println("The players health is: " + health);
51 | }
52 | }
53 | ```
54 |
55 | ```java
56 | new Server(1338, new PostOverride(), true, "cloud9secretstrats");
57 | ```
58 |
59 | You must also have a valid ```gamestate_integration_x.cfg``` file in your ```[Counter-Strike Global Offensive]\csgo\cfg\``` folder. A blank gamestate_integration file is provided here:
60 | ```
61 | "CSGOState Test v0.1"
62 | {
63 | "uri" "http://127.0.0.1:1338"
64 | "timeout" "5.0"
65 | "data"
66 | {
67 | "provider" "1"
68 | "map" "1"
69 | "round" "1"
70 | "player_id" "1"
71 | "player_state" "1"
72 | "player_weapons" "1"
73 | "player_match_stats" "1"
74 | }
75 | }
76 | ```
77 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/Info.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate;
2 |
3 | public class Info {
4 | private Server server;
5 |
6 | public Info(Server server) {
7 | this.server = server;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Added.java:
--------------------------------------------------------------------------------
1 |
2 | package com.brekcel.csgostate.JSON;
3 |
4 | import javax.annotation.Generated;
5 |
6 | //Added is currently bugged, sometimes returning boolean values instead of the expected Object
7 | @Generated("org.jsonschema2pojo")
8 | public class Added {
9 | //
10 | // @SerializedName("player")
11 | // @Expose
12 | // private Player__ player;
13 | //
14 | // /**
15 | // *
16 | // * @return
17 | // * The player
18 | // */
19 | // public Player__ getPlayer() {
20 | // return player;
21 | // }
22 | //
23 | // /**
24 | // *
25 | // * @param player
26 | // * The player
27 | // */
28 | // public void setPlayer(Player__ player) {
29 | // this.player = player;
30 | // }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Auth.java:
--------------------------------------------------------------------------------
1 |
2 | package com.brekcel.csgostate.JSON;
3 |
4 | import javax.annotation.Generated;
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | @Generated("org.jsonschema2pojo")
9 | public class Auth {
10 |
11 | @SerializedName("token")
12 | @Expose
13 | private String token;
14 |
15 | /**
16 | *
17 | * @return
18 | * The token
19 | */
20 | public String getToken() {
21 | return token;
22 | }
23 |
24 | /**
25 | *
26 | * @param token
27 | * The token
28 | */
29 | public void setToken(String token) {
30 | this.token = token;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/JsonResponse.java:
--------------------------------------------------------------------------------
1 |
2 | package com.brekcel.csgostate.JSON;
3 |
4 | import javax.annotation.Generated;
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | @Generated("org.jsonschema2pojo")
9 | public class JsonResponse {
10 |
11 | @SerializedName("provider")
12 | @Expose
13 | private Provider provider;
14 | @SerializedName("map")
15 | @Expose
16 | private Map map;
17 | @SerializedName("player")
18 | @Expose
19 | private Player player;
20 | @SerializedName("auth")
21 | @Expose
22 | private Auth auth;
23 | @SerializedName("previously")
24 | @Expose
25 | private Previously previously;
26 | @SerializedName("round")
27 | @Expose
28 | private Round round;
29 | @SerializedName("added")
30 | @Expose
31 | private Added added;
32 |
33 | /**
34 | *
35 | * @return
36 | * The provider
37 | */
38 | public Provider getProvider() {
39 | return provider;
40 | }
41 |
42 | /**
43 | *
44 | * @param provider
45 | * The provider
46 | */
47 | public void setProvider(Provider provider) {
48 | this.provider = provider;
49 | }
50 |
51 | /**
52 | *
53 | * @return
54 | * The map
55 | */
56 | public Map getMap() {
57 | return map;
58 | }
59 |
60 | /**
61 | *
62 | * @param map
63 | * The map
64 | */
65 | public void setMap(Map map) {
66 | this.map = map;
67 | }
68 |
69 | /**
70 | *
71 | * @return
72 | * The player
73 | */
74 | public Player getPlayer() {
75 | return player;
76 | }
77 |
78 | /**
79 | *
80 | * @param player
81 | * The player
82 | */
83 | public void setPlayer(Player player) {
84 | this.player = player;
85 | }
86 |
87 | /**
88 | *
89 | * @return
90 | * The auth
91 | */
92 | public Auth getAuth() {
93 | return auth;
94 | }
95 |
96 | /**
97 | *
98 | * @param auth
99 | * The auth
100 | */
101 | public void setAuth(Auth auth) {
102 | this.auth = auth;
103 | }
104 |
105 | /**
106 | *
107 | * @return
108 | * The previously
109 | */
110 | public Previously getPreviously() {
111 | return previously;
112 | }
113 |
114 | /**
115 | *
116 | * @param previously
117 | * The previously
118 | */
119 | public void setPreviously(Previously previously) {
120 | this.previously = previously;
121 | }
122 |
123 | /**
124 | *
125 | * @return
126 | * The round
127 | */
128 | public Round getRound() {
129 | return round;
130 | }
131 |
132 | /**
133 | *
134 | * @param round
135 | * The round
136 | */
137 | public void setRound(Round round) {
138 | this.round = round;
139 | }
140 |
141 | /**
142 | *
143 | * @return
144 | * The added
145 | */
146 | public Added getAdded() {
147 | return added;
148 | }
149 |
150 | /**
151 | *
152 | * @param added
153 | * The added
154 | */
155 | public void setAdded(Added added) {
156 | this.added = added;
157 | }
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Map.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.JSON;
2 |
3 | import javax.annotation.Generated;
4 |
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | @Generated("org.jsonschema2pojo")
9 | public class Map {
10 | @SerializedName("name")
11 | @Expose
12 | private String name;
13 | @SerializedName("mode")
14 | @Expose
15 | private String mode;
16 | @SerializedName("phase")
17 | @Expose
18 | private String phase;
19 | @SerializedName("round")
20 | @Expose
21 | private Integer round;
22 | @SerializedName("team_ct")
23 | @Expose
24 | private Team teamCt;
25 | @SerializedName("team_t")
26 | @Expose
27 | private Team teamT;
28 |
29 | /**
30 | *
31 | * @return
32 | * The mode
33 | */
34 | public String getMode() {
35 | return mode;
36 | }
37 |
38 | /**
39 | *
40 | * @param mode
41 | * The mode
42 | */
43 | public void setMode(String mode) {
44 | this.mode = mode;
45 | }
46 |
47 | /**
48 | *
49 | * @return
50 | * The name
51 | */
52 | public String getName() {
53 | return name;
54 | }
55 |
56 | /**
57 | *
58 | * @param name
59 | * The name
60 | */
61 | public void setName(String name) {
62 | this.name = name;
63 | }
64 |
65 | /**
66 | *
67 | * @return
68 | * The phase
69 | */
70 | public String getPhase() {
71 | return phase;
72 | }
73 |
74 | /**
75 | *
76 | * @param phase
77 | * The phase
78 | */
79 | public void setPhase(String phase) {
80 | this.phase = phase;
81 | }
82 |
83 | /**
84 | *
85 | * @return
86 | * The round
87 | */
88 | public Integer getRound() {
89 | return round;
90 | }
91 |
92 | /**
93 | *
94 | * @param round
95 | * The round
96 | */
97 | public void setRound(Integer round) {
98 | this.round = round;
99 | }
100 |
101 | /**
102 | *
103 | * @return
104 | * The teamCt
105 | */
106 | public Team getTeamCt() {
107 | return teamCt;
108 | }
109 |
110 | /**
111 | *
112 | * @param teamCt
113 | * The team_ct
114 | */
115 | public void setTeamCt(Team teamCt) {
116 | this.teamCt = teamCt;
117 | }
118 |
119 | /**
120 | *
121 | * @return
122 | * The teamT
123 | */
124 | public Team getTeamT() {
125 | return teamT;
126 | }
127 |
128 | /**
129 | *
130 | * @param teamT
131 | * The team_t
132 | */
133 | public void setTeamT(Team teamT) {
134 | this.teamT = teamT;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/MatchStats.java:
--------------------------------------------------------------------------------
1 |
2 | package com.brekcel.csgostate.JSON;
3 |
4 | import javax.annotation.Generated;
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | @Generated("org.jsonschema2pojo")
9 | public class MatchStats {
10 |
11 | @SerializedName("kills")
12 | @Expose
13 | private Integer kills;
14 | @SerializedName("assists")
15 | @Expose
16 | private Integer assists;
17 | @SerializedName("deaths")
18 | @Expose
19 | private Integer deaths;
20 | @SerializedName("mvps")
21 | @Expose
22 | private Integer mvps;
23 | @SerializedName("score")
24 | @Expose
25 | private Integer score;
26 |
27 | /**
28 | *
29 | * @return
30 | * The kills
31 | */
32 | public Integer getKills() {
33 | return kills;
34 | }
35 |
36 | /**
37 | *
38 | * @param kills
39 | * The kills
40 | */
41 | public void setKills(Integer kills) {
42 | this.kills = kills;
43 | }
44 |
45 | /**
46 | *
47 | * @return
48 | * The assists
49 | */
50 | public Integer getAssists() {
51 | return assists;
52 | }
53 |
54 | /**
55 | *
56 | * @param assists
57 | * The assists
58 | */
59 | public void setAssists(Integer assists) {
60 | this.assists = assists;
61 | }
62 |
63 | /**
64 | *
65 | * @return
66 | * The deaths
67 | */
68 | public Integer getDeaths() {
69 | return deaths;
70 | }
71 |
72 | /**
73 | *
74 | * @param deaths
75 | * The deaths
76 | */
77 | public void setDeaths(Integer deaths) {
78 | this.deaths = deaths;
79 | }
80 |
81 | /**
82 | *
83 | * @return
84 | * The mvps
85 | */
86 | public Integer getMvps() {
87 | return mvps;
88 | }
89 |
90 | /**
91 | *
92 | * @param mvps
93 | * The mvps
94 | */
95 | public void setMvps(Integer mvps) {
96 | this.mvps = mvps;
97 | }
98 |
99 | /**
100 | *
101 | * @return
102 | * The score
103 | */
104 | public Integer getScore() {
105 | return score;
106 | }
107 |
108 | /**
109 | *
110 | * @param score
111 | * The score
112 | */
113 | public void setScore(Integer score) {
114 | this.score = score;
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Player.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.JSON;
2 |
3 | import java.util.LinkedHashMap;
4 |
5 | import javax.annotation.Generated;
6 |
7 | import com.google.gson.annotations.Expose;
8 | import com.google.gson.annotations.SerializedName;
9 |
10 | @Generated("org.jsonschema2pojo")
11 | public class Player {
12 | @SerializedName("steamid")
13 | @Expose
14 | private String steamid;
15 | @SerializedName("name")
16 | @Expose
17 | private String name;
18 | @SerializedName("team")
19 | @Expose
20 | private String team;
21 | @SerializedName("activity")
22 | @Expose
23 | private String activity;
24 | @SerializedName("state")
25 | @Expose
26 | private State state;
27 | @SerializedName("weapons")
28 | @Expose
29 | private LinkedHashMap weapons;
30 | // private Weapons weapons;
31 | @SerializedName("match_stats")
32 | @Expose
33 | private MatchStats matchStats;
34 |
35 | /**
36 | *
37 | * @return
38 | * The steamid
39 | */
40 | public String getSteamid() {
41 | return steamid;
42 | }
43 |
44 | /**
45 | *
46 | * @param steamid
47 | * The steamid
48 | */
49 | public void setSteamid(String steamid) {
50 | this.steamid = steamid;
51 | }
52 |
53 | /**
54 | *
55 | * @return
56 | * The name
57 | */
58 | public String getName() {
59 | return name;
60 | }
61 |
62 | /**
63 | *
64 | * @param name
65 | * The name
66 | */
67 | public void setName(String name) {
68 | this.name = name;
69 | }
70 |
71 | /**
72 | *
73 | * @return
74 | * The team
75 | */
76 | public String getTeam() {
77 | return team;
78 | }
79 |
80 | /**
81 | *
82 | * @param team
83 | * The team
84 | */
85 | public void setTeam(String team) {
86 | this.team = team;
87 | }
88 |
89 | /**
90 | *
91 | * @return
92 | * The activity
93 | */
94 | public String getActivity() {
95 | return activity;
96 | }
97 |
98 | /**
99 | *
100 | * @param activity
101 | * The activity
102 | */
103 | public void setActivity(String activity) {
104 | this.activity = activity;
105 | }
106 |
107 | /**
108 | *
109 | * @return
110 | * The state
111 | */
112 | public State getState() {
113 | return state;
114 | }
115 |
116 | /**
117 | *
118 | * @param state
119 | * The state
120 | */
121 | public void setState(State state) {
122 | this.state = state;
123 | }
124 |
125 | /**
126 | *
127 | * @return
128 | * The weapons
129 | */
130 | public LinkedHashMap getWeapons() {
131 | return weapons;
132 | }
133 |
134 | /**
135 | *
136 | * @param weapons
137 | * The weapons
138 | */
139 | public void setWeapons(LinkedHashMap weapons) {
140 | this.weapons = weapons;
141 | }
142 |
143 | /**
144 | *
145 | * @return
146 | * The matchStats
147 | */
148 | public MatchStats getMatchStats() {
149 | return matchStats;
150 | }
151 |
152 | /**
153 | *
154 | * @param matchStats
155 | * The match_stats
156 | */
157 | public void setMatchStats(MatchStats matchStats) {
158 | this.matchStats = matchStats;
159 | }
160 |
161 | //TODO: Create this method
162 | //ALWAYS goes in order of: KNIFE, PRIMARY, SECONDARY, NADE0, NADE1, NADE2, NADE3, TASER, BOMB
163 | public Weapon[] getWeaponsArr() {
164 | Weapon[] weapons = new Weapon[9];
165 | return weapons;
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Previously.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.JSON;
2 |
3 | import javax.annotation.Generated;
4 |
5 | //Previously is currently bugged, sometimes returning boolean values instead of the expected Object
6 | @Generated("org.jsonschema2pojo")
7 | public class Previously {
8 | // @SerializedName("map")
9 | // @Expose
10 | // private Map map;
11 | // @SerializedName("round")
12 | // @Expose
13 | // private Round round;
14 | // @SerializedName("player")
15 | // @Expose
16 | // private Player player;
17 | //
18 | // /**
19 | // *
20 | // * @return
21 | // * The map
22 | // */
23 | // public Map getMap() {
24 | // return map;
25 | // }
26 | //
27 | // /**
28 | // *
29 | // * @param map
30 | // * The map
31 | // */
32 | // public void setMap(Map map) {
33 | // this.map = map;
34 | // }
35 | //
36 | // /**
37 | // *
38 | // * @return
39 | // * The round
40 | // */
41 | // public Round getRound() {
42 | // return round;
43 | // }
44 | //
45 | // /**
46 | // *
47 | // * @param map
48 | // * The round
49 | // */
50 | // public void setRound(Round round) {
51 | // this.round = round;
52 | // }
53 | //
54 | // /**
55 | // *
56 | // * @return
57 | // * The player
58 | // */
59 | // public Player getPlayer() {
60 | // return player;
61 | // }
62 | //
63 | // /**
64 | // *
65 | // * @param player
66 | // * The player
67 | // */
68 | // public void setPlayer(Player player) {
69 | // this.player = player;
70 | // }
71 | }
72 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Provider.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.JSON;
2 |
3 | import javax.annotation.Generated;
4 |
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | @Generated("org.jsonschema2pojo")
9 | public class Provider {
10 | @SerializedName("name")
11 | @Expose
12 | private String name;
13 | @SerializedName("appid")
14 | @Expose
15 | private Integer appid;
16 | @SerializedName("version")
17 | @Expose
18 | private Integer version;
19 | @SerializedName("steamid")
20 | @Expose
21 | private String steamid;
22 | @SerializedName("timestamp")
23 | @Expose
24 | private Long timestamp;
25 |
26 | /**
27 | *
28 | * @return
29 | * The name
30 | */
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | /**
36 | *
37 | * @param name
38 | * The name
39 | */
40 | public void setName(String name) {
41 | this.name = name;
42 | }
43 |
44 | /**
45 | *
46 | * @return
47 | * The appid
48 | */
49 | public Integer getAppid() {
50 | return appid;
51 | }
52 |
53 | /**
54 | *
55 | * @param appid
56 | * The appid
57 | */
58 | public void setAppid(Integer appid) {
59 | this.appid = appid;
60 | }
61 |
62 | /**
63 | *
64 | * @return
65 | * The version
66 | */
67 | public Integer getVersion() {
68 | return version;
69 | }
70 |
71 | /**
72 | *
73 | * @param version
74 | * The version
75 | */
76 | public void setVersion(Integer version) {
77 | this.version = version;
78 | }
79 |
80 | /**
81 | *
82 | * @return
83 | * The steamid
84 | */
85 | public String getSteamid() {
86 | return steamid;
87 | }
88 |
89 | /**
90 | *
91 | * @param steamid
92 | * The steamid
93 | */
94 | public void setSteamid(String steamid) {
95 | this.steamid = steamid;
96 | }
97 |
98 | /**
99 | *
100 | * @return
101 | * The timestamp
102 | */
103 | public Long getTimestamp() {
104 | return timestamp;
105 | }
106 |
107 | /**
108 | *
109 | * @param timestamp
110 | * The timestamp
111 | */
112 | public void setTimestamp(Long timestamp) {
113 | this.timestamp = timestamp;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Round.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.JSON;
2 |
3 | import javax.annotation.Generated;
4 |
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | @Generated("org.jsonschema2pojo")
9 | public class Round {
10 | @SerializedName("phase")
11 | @Expose
12 | private String phase;
13 | @SerializedName("win_team")
14 | @Expose
15 | private String winTeam;
16 | @SerializedName("bomb")
17 | @Expose
18 | private String bomb;
19 |
20 | /**
21 | *
22 | * @return
23 | * The phase
24 | */
25 | public String getPhase() {
26 | return phase;
27 | }
28 |
29 | /**
30 | *
31 | * @param phase
32 | * The phase
33 | */
34 | public void setPhase(String phase) {
35 | this.phase = phase;
36 | }
37 |
38 | /**
39 | *
40 | * @return
41 | * The winTeam
42 | */
43 | public String getWinTeam() {
44 | return winTeam;
45 | }
46 |
47 | /**
48 | *
49 | * @param winTeam
50 | * The win_team
51 | */
52 | public void setWinTeam(String winTeam) {
53 | this.winTeam = winTeam;
54 | }
55 |
56 | /**
57 | *
58 | * @return
59 | * The bomb
60 | */
61 | public String getBomb() {
62 | return bomb;
63 | }
64 |
65 | /**
66 | *
67 | * @param bomb
68 | * The bomb
69 | */
70 | public void setBomb(String bomb) {
71 | this.bomb = bomb;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/State.java:
--------------------------------------------------------------------------------
1 |
2 | package com.brekcel.csgostate.JSON;
3 |
4 | import javax.annotation.Generated;
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | @Generated("org.jsonschema2pojo")
9 | public class State {
10 |
11 | @SerializedName("health")
12 | @Expose
13 | private Integer health;
14 | @SerializedName("armor")
15 | @Expose
16 | private Integer armor;
17 | @SerializedName("helmet")
18 | @Expose
19 | private Boolean helmet;
20 | @SerializedName("flashed")
21 | @Expose
22 | private Integer flashed;
23 | @SerializedName("smoked")
24 | @Expose
25 | private Integer smoked;
26 | @SerializedName("burning")
27 | @Expose
28 | private Integer burning;
29 | @SerializedName("money")
30 | @Expose
31 | private Integer money;
32 | @SerializedName("round_kills")
33 | @Expose
34 | private Integer roundKills;
35 | @SerializedName("round_killhs")
36 | @Expose
37 | private Integer roundKillhs;
38 |
39 | /**
40 | *
41 | * @return
42 | * The health
43 | */
44 | public Integer getHealth() {
45 | return health;
46 | }
47 |
48 | /**
49 | *
50 | * @param health
51 | * The health
52 | */
53 | public void setHealth(Integer health) {
54 | this.health = health;
55 | }
56 |
57 | /**
58 | *
59 | * @return
60 | * The armor
61 | */
62 | public Integer getArmor() {
63 | return armor;
64 | }
65 |
66 | /**
67 | *
68 | * @param armor
69 | * The armor
70 | */
71 | public void setArmor(Integer armor) {
72 | this.armor = armor;
73 | }
74 |
75 | /**
76 | *
77 | * @return
78 | * The helmet
79 | */
80 | public Boolean getHelmet() {
81 | return helmet;
82 | }
83 |
84 | /**
85 | *
86 | * @param helmet
87 | * The helmet
88 | */
89 | public void setHelmet(Boolean helmet) {
90 | this.helmet = helmet;
91 | }
92 |
93 | /**
94 | *
95 | * @return
96 | * The flashed
97 | */
98 | public Integer getFlashed() {
99 | return flashed;
100 | }
101 |
102 | /**
103 | *
104 | * @param flashed
105 | * The flashed
106 | */
107 | public void setFlashed(Integer flashed) {
108 | this.flashed = flashed;
109 | }
110 |
111 | /**
112 | *
113 | * @return
114 | * The smoked
115 | */
116 | public Integer getSmoked() {
117 | return smoked;
118 | }
119 |
120 | /**
121 | *
122 | * @param smoked
123 | * The smoked
124 | */
125 | public void setSmoked(Integer smoked) {
126 | this.smoked = smoked;
127 | }
128 |
129 | /**
130 | *
131 | * @return
132 | * The burning
133 | */
134 | public Integer getBurning() {
135 | return burning;
136 | }
137 |
138 | /**
139 | *
140 | * @param burning
141 | * The burning
142 | */
143 | public void setBurning(Integer burning) {
144 | this.burning = burning;
145 | }
146 |
147 | /**
148 | *
149 | * @return
150 | * The money
151 | */
152 | public Integer getMoney() {
153 | return money;
154 | }
155 |
156 | /**
157 | *
158 | * @param money
159 | * The money
160 | */
161 | public void setMoney(Integer money) {
162 | this.money = money;
163 | }
164 |
165 | /**
166 | *
167 | * @return
168 | * The roundKills
169 | */
170 | public Integer getRoundKills() {
171 | return roundKills;
172 | }
173 |
174 | /**
175 | *
176 | * @param roundKills
177 | * The round_kills
178 | */
179 | public void setRoundKills(Integer roundKills) {
180 | this.roundKills = roundKills;
181 | }
182 |
183 | /**
184 | *
185 | * @return
186 | * The roundKillhs
187 | */
188 | public Integer getRoundKillhs() {
189 | return roundKillhs;
190 | }
191 |
192 | /**
193 | *
194 | * @param roundKillhs
195 | * The round_killhs
196 | */
197 | public void setRoundKillhs(Integer roundKillhs) {
198 | this.roundKillhs = roundKillhs;
199 | }
200 |
201 | }
202 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Team.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.JSON;
2 |
3 | import com.google.gson.annotations.Expose;
4 | import com.google.gson.annotations.SerializedName;
5 |
6 | public class Team {
7 | @SerializedName("score")
8 | @Expose
9 | private Integer score;
10 | @SerializedName("name")
11 | @Expose
12 | private String name;
13 | @SerializedName("flag")
14 | @Expose
15 | private String flag;
16 |
17 | /**
18 | *
19 | * @return
20 | * The flag
21 | */
22 | public String getFlag() {
23 | return flag;
24 | }
25 |
26 | public void setFlag(String flag) {
27 | this.flag = flag;
28 | }
29 |
30 | /**
31 | *
32 | * @return
33 | * The name
34 | */
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | /**
44 | *
45 | * @return
46 | * The score
47 | */
48 | public Integer getScore() {
49 | return score;
50 | }
51 |
52 | /**
53 | *
54 | * @param score
55 | * The score
56 | */
57 | public void setScore(Integer score) {
58 | this.score = score;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/JSON/Weapon.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.JSON;
2 |
3 | import com.google.gson.annotations.Expose;
4 | import com.google.gson.annotations.SerializedName;
5 |
6 | public class Weapon {
7 | @SerializedName("name")
8 | @Expose
9 | private String name;
10 | @SerializedName("paintkit")
11 | @Expose
12 | private String paintkit;
13 | @SerializedName("type")
14 | @Expose
15 | private String type;
16 | @SerializedName("ammo_clip")
17 | @Expose
18 | private Integer ammoClip;
19 | @SerializedName("ammo_clip_max")
20 | @Expose
21 | private Integer ammoClipMax;
22 | @SerializedName("ammo_reserve")
23 | @Expose
24 | private Integer ammoReserve;
25 | @SerializedName("state")
26 | @Expose
27 | private String state;
28 |
29 | /**
30 | *
31 | * @return
32 | * The name
33 | */
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | /**
39 | *
40 | * @param name
41 | * The name
42 | */
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 |
47 | /**
48 | *
49 | * @return
50 | * The paintkit
51 | */
52 | public String getPaintkit() {
53 | return paintkit;
54 | }
55 |
56 | /**
57 | *
58 | * @param paintkit
59 | * The paintkit
60 | */
61 | public void setPaintkit(String paintkit) {
62 | this.paintkit = paintkit;
63 | }
64 |
65 | /**
66 | *
67 | * @return
68 | * The type
69 | */
70 | public String getType() {
71 | return type;
72 | }
73 |
74 | /**
75 | *
76 | * @param type
77 | * The type
78 | */
79 | public void setType(String type) {
80 | this.type = type;
81 | }
82 |
83 | /**
84 | *
85 | * @return
86 | * The ammoClip
87 | */
88 | public Integer getAmmoClip() {
89 | return ammoClip;
90 | }
91 |
92 | /**
93 | *
94 | * @param ammoClip
95 | * The ammo_clip
96 | */
97 | public void setAmmoClip(Integer ammoClip) {
98 | this.ammoClip = ammoClip;
99 | }
100 |
101 | /**
102 | *
103 | * @return
104 | * The ammoClipMax
105 | */
106 | public Integer getAmmoClipMax() {
107 | return ammoClipMax;
108 | }
109 |
110 | /**
111 | *
112 | * @param ammoClipMax
113 | * The ammo_clip_max
114 | */
115 | public void setAmmoClipMax(Integer ammoClipMax) {
116 | this.ammoClipMax = ammoClipMax;
117 | }
118 |
119 | /**
120 | *
121 | * @return
122 | * The ammoReserve
123 | */
124 | public Integer getAmmoReserve() {
125 | return ammoReserve;
126 | }
127 |
128 | /**
129 | *
130 | * @param ammoReserve
131 | * The ammo_reserve
132 | */
133 | public void setAmmoReserve(Integer ammoReserve) {
134 | this.ammoReserve = ammoReserve;
135 | }
136 |
137 | /**
138 | *
139 | * @return
140 | * The state
141 | */
142 | public String getState() {
143 | return state;
144 | }
145 |
146 | /**
147 | *
148 | * @param state
149 | * The state
150 | */
151 | public void setState(String state) {
152 | this.state = state;
153 | }
154 |
155 | public Weapon() {}
156 | }
157 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/Server.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate;
2 |
3 | import java.io.IOException;
4 | import java.net.InetSocketAddress;
5 | import java.util.concurrent.Executors;
6 |
7 | import com.brekcel.csgostate.JSON.JsonResponse;
8 | import com.brekcel.csgostate.post.PostHandler;
9 | import com.brekcel.csgostate.post.PostReceiver;
10 | import com.sun.net.httpserver.HttpServer;
11 |
12 | public class Server {
13 | private HttpServer serv;
14 | private String authToken;
15 | private int port;
16 | private PostReceiver receive;
17 | private Info info;
18 | public boolean onlyUser;
19 |
20 | public Server(int port, PostHandler postHandle, boolean onlyUser, String authToken) throws IOException {
21 | this.port = port;
22 | this.authToken = authToken;
23 | this.onlyUser = onlyUser;
24 | serv = HttpServer.create(new InetSocketAddress(port), 0);
25 | receive = new PostReceiver(this, postHandle);
26 | serv.createContext("/", receive);
27 | serv.setExecutor(Executors.newCachedThreadPool());
28 | serv.start();
29 | info = new Info(this);
30 | System.out.println("Server successfully started on port " + port + (authToken == null ? "." : " with Auth Token: " + authToken));
31 | }
32 |
33 | public Server(int port, PostHandler postHandle, boolean onlyUser) throws IOException {
34 | new Server(port, postHandle, onlyUser, null);
35 | }
36 |
37 | public Info getInfo() {
38 | return info;
39 | }
40 |
41 | public JsonResponse getCurrentJSR() {
42 | return receive.getCurrentJSR();
43 | }
44 |
45 | public String getAuthToken() {
46 | return authToken;
47 | }
48 |
49 | public void stop() {
50 | serv.stop(0);
51 | }
52 |
53 | public int getPort() {
54 | return port;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/post/PostHandler.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.post;
2 |
3 | import com.brekcel.csgostate.JSON.JsonResponse;
4 | import com.brekcel.csgostate.JSON.Map;
5 | import com.brekcel.csgostate.JSON.MatchStats;
6 | import com.brekcel.csgostate.JSON.Player;
7 | import com.brekcel.csgostate.JSON.Round;
8 | import com.brekcel.csgostate.JSON.State;
9 | import com.brekcel.csgostate.JSON.Weapon;
10 |
11 | // TODO: Change Strings to enums?
12 | public interface PostHandler {
13 | /**
14 | * Called when a new JsonResponse is received.
15 | *
16 | * @param jsonResponse
17 | * The jsonResponse that was just received.
18 | */
19 | public void receivedJsonResponse(JsonResponse jsonResponse);
20 |
21 | // START OF MAP
22 | /**
23 | * Called when Map is received, and a previous Map value did not exist.
24 | * Should only be called when a player joins a game from a menu.
25 | *
26 | * @param map
27 | * The Map object that was just received.
28 | */
29 | public void newMap(Map map);
30 |
31 | /**
32 | * Called when a Map object is received.
33 | *
34 | * @param map
35 | * The Map object that was just received.
36 | */
37 | public void receivedMap(Map map);
38 |
39 | /**
40 | * Called when a Map previously existed, but no longer does.
41 | * I.E. going from a Game to the main menu.
42 | */
43 | public void mapReset();
44 |
45 | /**
46 | * Called when the name of the map is changed.
47 | *
48 | * @param mapName
49 | * The name of the new map.
50 | */
51 | public void mapNameChange(String mapName);
52 |
53 | /**
54 | * Called when the gamemode changes
55 | *
56 | * @param mode
57 | * The name of the new mode.
58 | */
59 | public void modeChange(String mode);
60 |
61 | /**
62 | * Called when the round changes.
63 | *
64 | * @param round
65 | * The new round.
66 | */
67 | public void roundChange(int round);
68 |
69 | /**
70 | * Called when a Team changes it's name.
71 | *
72 | * @param team
73 | * Which team changed it's name. Either: "ct" or "t".
74 | * @param name
75 | * The new name of the team.
76 | */
77 | public void teamNameChange(String team, String name);
78 |
79 | /**
80 | * Called when the score changes.
81 | *
82 | * @param ct
83 | * The CT's Score.
84 | * @param t
85 | * The T's Score.
86 | */
87 | public void scoreChange(int ct, int t);
88 |
89 | /**
90 | * Called when the Map's Phase Changes.
91 | *
92 | * @param phase
93 | * The Map's new phase.
94 | */
95 | public void phaseChange(String phase);
96 | // END OF MAP
97 |
98 | // START OF ROUND
99 | /**
100 | * Called when a Round is received, and no previous round existed.
101 | *
102 | * @param round
103 | * The Round received.
104 | */
105 | public void newRound(Round round);
106 |
107 | /**
108 | * Called when a Round is received.
109 | *
110 | * @param round
111 | * The Round received.
112 | */
113 | public void receivedRound(Round round);
114 |
115 | /**
116 | * Called when a round previously existed, but no longer does.
117 | */
118 | public void roundReset();
119 |
120 | /**
121 | * Called when the bomb is planted.
122 | *
123 | * As of
125 | * 12.17.15's 1.35.1.6 Update, the bomb's state is randomly delayed when
126 | * user is not a spectator.
127 | */
128 | public void bombPlanted();
129 |
130 | /**
131 | * Called when the bomb explodes.
132 | */
133 | public void bombExploded();
134 |
135 | /**
136 | * Called when the bomb is defused.
137 | */
138 | public void bombDefused();
139 |
140 | /**
141 | * Called when a team wins a round.
142 | *
143 | * @param team
144 | * The team that won the round. Either: "CT" or "T"
145 | */
146 | public void roundWinningTeamChange(String team);
147 |
148 | /**
149 | * Called when the round is live.
150 | *
151 | */
152 | public void roundLive();
153 |
154 | /**
155 | * Called when the round is in freezetime.
156 | */
157 | public void roundFreezeTime();
158 |
159 | /**
160 | * Called when the round is over.
161 | */
162 | public void roundOver();
163 | // END OF ROUND
164 |
165 | // START OF PLAYER
166 | /**
167 | * Called when a new Player is received and Player did not previously exist.
168 | *
169 | * @param player
170 | * The Player received.
171 | */
172 | public void newPlayer(Player player);
173 |
174 | /**
175 | * Called when a Player is received.
176 | *
177 | * @param player
178 | * The Player received.
179 | */
180 | public void receivedPlayer(Player player);
181 |
182 | /**
183 | * Called when a Player no longer exists, but did previously exist.
184 | */
185 | public void playerReset();
186 |
187 | /**
188 | * Called when a Players name changes.
189 | *
190 | * @param name
191 | * The new name.
192 | */
193 | public void playerNameChange(String name);
194 |
195 | /**
196 | * Called when the players SteamID changes.
197 | *
198 | * @param steamID
199 | * The new SteamID.
200 | */
201 | public void playerSteamIDChange(String steamID);
202 |
203 | /**
204 | * Called when the Players team changes.
205 | *
206 | * @param team
207 | * The new team.
208 | */
209 | public void playerTeamChange(String team);
210 |
211 | /**
212 | * Called when the Players activity changes.
213 | *
214 | * @param activity
215 | * The new activity.
216 | */
217 | public void playerActivityChange(String activity);
218 |
219 | /**
220 | * Called when the Players state changes.
221 | *
222 | * @param state
223 | * The new state.
224 | */
225 | public void playerStateChange(State state);
226 |
227 | // START OF PlayerState
228 | /**
229 | * Called when the Players health changes.
230 | *
231 | * @param health
232 | * The players current hp. Value is 0-100
233 | */
234 | public void playerHealthChange(int health);
235 |
236 | /**
237 | * Called when the Players armor value changes.
238 | *
239 | * @param armor
240 | * The players current armor. Value is 0-100
241 | */
242 | public void playerArmorChange(int armor);
243 |
244 | /**
245 | * Called when a player either buys a helmet, or loses it.
246 | *
247 | * @param helmet
248 | * If the player has a helmet or not.
249 | */
250 | public void playerHelmetChange(boolean helmet);
251 |
252 | /**
253 | * Called when the player is flashed.
254 | *
255 | * @param flashed
256 | * The value of how flashed the player is. Value is 0-255
257 | */
258 | public void playerFlashedChange(int flashed);
259 |
260 | /**
261 | * Called when the player walks into smoke.
262 | *
263 | * @param smoked
264 | * The value of how smoked they are. Value is 0-255
265 | */
266 | public void playerSmokeChange(int smoked);
267 |
268 | /**
269 | * Called when a player gets burned. By fire.
270 | *
271 | * @param burning
272 | * Not really sure... Value is 0-255. Full burn is 255, Not
273 | * burning is 0. Only seems possible to receive other values when
274 | * fire is dissipating.
275 | */
276 | public void playerBurningChange(int burning);
277 |
278 | /**
279 | * Called when the players money changes.
280 | *
281 | * @param money
282 | * How much money they have. Value is 0-mp_maxmoney [Set on
283 | * Server]
284 | */
285 | public void playerMoneyChange(int money);
286 |
287 | /**
288 | * Called when the players Round Kills changes.
289 | *
290 | * @param kills
291 | * How many kills they got this round.
292 | */
293 | public void playerRoundKillsChange(int kills);
294 |
295 | /**
296 | * Called when the players Round Kills Headshot changes.
297 | *
298 | * @param killsHS
299 | * How many headshots they got this round.
300 | */
301 | public void playerRoundKillsHSChange(int killsHS);
302 | // END OF PlayerState
303 |
304 | // Start of PlayerWeapons
305 | // TODO: Rework Weapons. They suck. Hard. //TODONE. Kinda.
306 | public void newWeapons(Weapon[] weapons);
307 |
308 | public void weaponsChange(Weapon[] weapons);
309 |
310 | public void weaponActiveChange(Weapon weapon);
311 |
312 | public void weaponShoot(Weapon weapon);
313 |
314 | public void weaponReload(Weapon weapon);
315 | // End of PlayerWeapons
316 |
317 | // Start of PlayerMatchStats
318 | /**
319 | * Called when the players MatchStats changes.
320 | *
321 | * @param ms
322 | * The received MatchStats
323 | */
324 | public void playerMatchStatsChange(MatchStats ms);
325 |
326 | /**
327 | * Called when MatchStats are received.
328 | *
329 | * @param ms
330 | * The MatchStats received.
331 | */
332 | public void playerMatchStatsReceived(MatchStats ms);
333 |
334 | /**
335 | * Called when the Players kill count change.
336 | *
337 | * @param kills
338 | * How many kills the player has.
339 | */
340 | public void playerMatchKillsChange(int kills);
341 |
342 | /**
343 | * Called when the Players Assist count changes.
344 | *
345 | * @param assists
346 | * How many assists the player has.
347 | */
348 | public void playerMatchAssistsChange(int assists);
349 |
350 | /**
351 | * Called when the Players death count changes.
352 | *
353 | * @param deaths
354 | * How many deaths the player has.
355 | */
356 | public void playerMatchDeathsChange(int deaths);
357 |
358 | /**
359 | * Called when the Players MVP count changes.
360 | *
361 | * @param mvps
362 | * How many MVP's the player has.
363 | */
364 | public void playerMatchMVPSChange(int mvps);
365 |
366 | /**
367 | * Called when the players score changes.
368 | *
369 | * @param score
370 | * The players score.
371 | */
372 | public void playerMatchScoreChange(int score);
373 | // End of PlayerMatchStats
374 | // END OF PLAYER
375 | }
376 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/post/PostHandlerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.post;
2 |
3 | import com.brekcel.csgostate.JSON.JsonResponse;
4 | import com.brekcel.csgostate.JSON.Map;
5 | import com.brekcel.csgostate.JSON.MatchStats;
6 | import com.brekcel.csgostate.JSON.Player;
7 | import com.brekcel.csgostate.JSON.Round;
8 | import com.brekcel.csgostate.JSON.State;
9 | import com.brekcel.csgostate.JSON.Weapon;
10 |
11 | // Simple class that implements PostHandler.
12 | // Use this when you only want to use specific methods from PostHandler.
13 | // If using ALL methods of PostHandler, might as well just implement that
14 | // instead of extending this.
15 | public class PostHandlerAdapter implements PostHandler {
16 | @Override
17 | public void receivedJsonResponse(JsonResponse jsonResponse) {}
18 |
19 | @Override
20 | public void newMap(Map map) {}
21 |
22 | @Override
23 | public void receivedMap(Map map) {}
24 |
25 | @Override
26 | public void mapReset() {}
27 |
28 | @Override
29 | public void mapNameChange(String mapName) {}
30 |
31 | @Override
32 | public void modeChange(String mode) {}
33 |
34 | @Override
35 | public void roundChange(int round) {}
36 |
37 | @Override
38 | public void teamNameChange(String team, String name) {}
39 |
40 | @Override
41 | public void scoreChange(int ct, int t) {}
42 |
43 | @Override
44 | public void phaseChange(String phase) {}
45 |
46 | @Override
47 | public void newRound(Round round) {}
48 |
49 | @Override
50 | public void receivedRound(Round round) {}
51 |
52 | @Override
53 | public void roundReset() {}
54 |
55 | @Override
56 | public void roundWinningTeamChange(String team) {}
57 |
58 | @Override
59 | public void newPlayer(Player player) {}
60 |
61 | @Override
62 | public void receivedPlayer(Player player) {}
63 |
64 | @Override
65 | public void playerReset() {}
66 |
67 | @Override
68 | public void playerNameChange(String name) {}
69 |
70 | @Override
71 | public void playerSteamIDChange(String steamID) {}
72 |
73 | @Override
74 | public void playerTeamChange(String team) {}
75 |
76 | @Override
77 | public void playerActivityChange(String activity) {}
78 |
79 | @Override
80 | public void playerStateChange(State state) {}
81 |
82 | @Override
83 | public void playerHealthChange(int health) {}
84 |
85 | @Override
86 | public void playerArmorChange(int armor) {}
87 |
88 | @Override
89 | public void playerHelmetChange(boolean helmet) {}
90 |
91 | @Override
92 | public void playerFlashedChange(int flashed) {}
93 |
94 | @Override
95 | public void playerSmokeChange(int smoked) {}
96 |
97 | @Override
98 | public void playerBurningChange(int burning) {}
99 |
100 | @Override
101 | public void playerMoneyChange(int money) {}
102 |
103 | @Override
104 | public void playerRoundKillsChange(int kills) {}
105 |
106 | @Override
107 | public void playerRoundKillsHSChange(int killsHS) {}
108 |
109 | @Override
110 | public void newWeapons(Weapon[] weapons) {}
111 |
112 | @Override
113 | public void weaponsChange(Weapon[] weapons) {}
114 |
115 | @Override
116 | public void weaponActiveChange(Weapon weapon) {}
117 |
118 | @Override
119 | public void weaponShoot(Weapon weapon) {}
120 |
121 | @Override
122 | public void weaponReload(Weapon weapon) {}
123 |
124 | @Override
125 | public void playerMatchStatsChange(MatchStats ms) {}
126 |
127 | @Override
128 | public void playerMatchKillsChange(int kills) {}
129 |
130 | @Override
131 | public void playerMatchAssistsChange(int assists) {}
132 |
133 | @Override
134 | public void playerMatchDeathsChange(int deaths) {}
135 |
136 | @Override
137 | public void playerMatchMVPSChange(int mvps) {}
138 |
139 | @Override
140 | public void playerMatchScoreChange(int score) {}
141 |
142 | @Override
143 | public void playerMatchStatsReceived(MatchStats ms) {}
144 |
145 | @Override
146 | public void bombPlanted() {}
147 |
148 | @Override
149 | public void bombExploded() {}
150 |
151 | @Override
152 | public void bombDefused() {}
153 |
154 | @Override
155 | public void roundLive() {}
156 |
157 | @Override
158 | public void roundFreezeTime() {}
159 |
160 | @Override
161 | public void roundOver() {}
162 | }
163 |
--------------------------------------------------------------------------------
/src/com/brekcel/csgostate/post/PostReceiver.java:
--------------------------------------------------------------------------------
1 | package com.brekcel.csgostate.post;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.BufferedWriter;
5 | import java.io.File;
6 | import java.io.FileWriter;
7 | import java.io.IOException;
8 | import java.io.InputStreamReader;
9 |
10 | import com.brekcel.csgostate.Server;
11 | import com.brekcel.csgostate.JSON.JsonResponse;
12 | import com.brekcel.csgostate.JSON.Map;
13 | import com.brekcel.csgostate.JSON.MatchStats;
14 | import com.brekcel.csgostate.JSON.Player;
15 | import com.brekcel.csgostate.JSON.Round;
16 | import com.brekcel.csgostate.JSON.State;
17 | import com.brekcel.csgostate.JSON.Weapon;
18 | import com.google.gson.Gson;
19 | import com.sun.net.httpserver.HttpExchange;
20 | import com.sun.net.httpserver.HttpHandler;
21 |
22 | public class PostReceiver implements HttpHandler {
23 | private PostHandler handle;
24 | private Server serv;
25 | private Gson gson;
26 | private BufferedWriter writer;
27 | private JsonResponse currentJSR;
28 |
29 | public PostReceiver(Server serv, PostHandler handle) {
30 | this.serv = serv;
31 | this.handle = handle;
32 | gson = new Gson();
33 | try {
34 | new File("A:/csgoLog.txt").createNewFile();
35 | writer = new BufferedWriter(new FileWriter(new File("A:/csgoLog.txt"), true));
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | }
39 | }
40 |
41 | @Override
42 | public void handle(HttpExchange exc) throws IOException {
43 | StringBuffer response = new StringBuffer();
44 | StringBuffer printResponse = new StringBuffer();
45 | try {
46 | BufferedReader in = new BufferedReader(new InputStreamReader(exc.getRequestBody()));
47 | String inl;
48 | while ((inl = in.readLine()) != null) {
49 | response.append(inl);
50 | printResponse.append(inl + "\n");
51 | }
52 | in.close();
53 | writer.write(response.toString());
54 | writer.newLine();
55 | writer.flush();
56 | JsonResponse jsr = gson.fromJson(response.toString(), JsonResponse.class);
57 | if ((jsr.getAuth() == null && serv.getAuthToken() != null) && (serv.getAuthToken() == null && jsr.getAuth() != null) && !jsr.getAuth().getToken().equals(serv.getAuthToken())) {
58 | System.out.println("Invalid connection attempt from: " + exc.getLocalAddress());
59 | return;
60 | }
61 | exc.sendResponseHeaders(200, -1);
62 | // System.out.println(response.toString());
63 | callMethods(jsr);
64 | } catch (Exception e) {
65 | System.out.println(printResponse.toString());
66 | e.printStackTrace();
67 | }
68 | }
69 |
70 | private void callMethods(JsonResponse jsr) {
71 | try {
72 | handle.receivedJsonResponse(jsr);
73 | if (currentJSR == null)
74 | currentJSR = new JsonResponse();
75 | // MAP
76 | if (jsr.getMap() != null) {
77 | handle.receivedMap(jsr.getMap());
78 | if (currentJSR.getMap() == null || !currentJSR.getMap().equals(jsr.getMap())) {
79 | Map nm = jsr.getMap();
80 | Map cm = currentJSR.getMap();
81 | if (currentJSR.getMap() == null) {
82 | handle.newMap(nm);
83 | if (nm.getMode() != null)
84 | handle.modeChange(nm.getMode());
85 | if (nm.getName() != null)
86 | handle.mapNameChange(nm.getName());
87 | if (nm.getRound() != null)
88 | handle.roundChange(nm.getRound());
89 | if (nm.getTeamCt().getName() != null || nm.getTeamT().getName() != null)
90 | handle.teamNameChange(nm.getTeamCt().getName(), nm.getTeamT().getName());
91 | if (nm.getTeamCt().getScore() != null && nm.getTeamT() != null)
92 | handle.scoreChange(nm.getTeamCt().getScore(), nm.getTeamT().getScore());
93 | if (nm.getPhase() != null)
94 | handle.phaseChange(nm.getPhase());
95 | } else {
96 | if (nm.getMode() != null && (cm.getMode() == null || !cm.getMode().equals(nm.getMode()))) {
97 | handle.modeChange(nm.getMode());
98 | }
99 | if (nm.getName() != null && (cm.getName() == null || !cm.getName().equals(nm.getName()))) {
100 | handle.mapNameChange(nm.getName());
101 | }
102 | if (nm.getPhase() != null && (cm.getPhase() == null || !cm.getPhase().equals(nm.getPhase()))) {
103 | handle.phaseChange(nm.getPhase());
104 | }
105 | if (nm.getPhase() != null && (cm.getRound() == null || cm.getRound() != nm.getRound())) {
106 | handle.roundChange(nm.getRound());
107 | }
108 | if ((nm.getTeamCt().getScore() != null && nm.getTeamT().getScore() != null) && (cm.getTeamCt().getScore() == null || cm.getTeamT().getScore() == null || cm.getTeamCt().getScore() != nm.getTeamCt().getScore() || cm.getTeamT().getScore() != nm.getTeamT().getScore())) {
109 | handle.scoreChange(nm.getTeamCt().getScore(), nm.getTeamT().getScore());
110 | }
111 | if ((nm.getTeamCt().getName() != null && (cm.getTeamCt().getName() == null || !cm.getTeamCt().getName().equals(nm.getTeamCt().getName())))) {
112 | handle.teamNameChange("ct", nm.getTeamCt().getName());
113 | }
114 | if ((nm.getTeamT().getName() != null && (cm.getTeamT().getName() == null || !cm.getTeamT().getName().equals(cm.getTeamT().getName())))) {
115 | handle.teamNameChange("t", nm.getTeamT().getName());
116 | }
117 | if ((nm.getTeamCt().getName() == null && cm.getTeamCt().getName() != null)) {
118 | handle.teamNameChange("ct", nm.getTeamCt().getName());
119 | }
120 | if ((nm.getTeamT().getName() == null && cm.getTeamT().getName() != null)) {
121 | handle.teamNameChange("t", nm.getTeamT().getName());
122 | }
123 | }
124 | }
125 | } else {
126 | handle.mapReset();
127 | }
128 | // ROUND
129 | if (jsr.getRound() != null) {
130 | if (currentJSR.getRound() == null || !currentJSR.getRound().equals(jsr.getRound())) {
131 | Round nr = jsr.getRound();
132 | Round cr = currentJSR.getRound();
133 | if (currentJSR.getRound() == null) {
134 | if (nr.getPhase() != null) {
135 | if (nr.getPhase().equals("live"))
136 | handle.roundLive();
137 | else if (nr.getPhase().equals("freezetime"))
138 | handle.roundFreezeTime();
139 | else if (nr.getPhase().equals("over"))
140 | handle.roundOver();
141 | }
142 | if (nr.getBomb() != null) {
143 | if (nr.getBomb().equals("planted"))
144 | handle.bombPlanted();
145 | else if (nr.getBomb().equals("exploded"))
146 | handle.bombExploded();
147 | else if (nr.getBomb().equals("defused"))
148 | handle.bombDefused();
149 | }
150 | if (nr.getWinTeam() != null)
151 | handle.roundWinningTeamChange(nr.getWinTeam());
152 | } else {
153 | if (nr.getBomb() != null && (cr.getBomb() == null || !cr.getBomb().equals(nr.getBomb()))) {
154 | if (nr.getBomb().equals("planted"))
155 | handle.bombPlanted();
156 | else if (nr.getBomb().equals("exploded"))
157 | handle.bombExploded();
158 | else if (nr.getBomb().equals("defused"))
159 | handle.bombDefused();
160 | }
161 | // Needs to be tested.
162 | // Tested for 5 minutes. Worked.
163 | if (nr.getWinTeam() != null && (cr.getPhase() != null && !cr.getPhase().equals(nr.getPhase()))) {
164 | handle.roundWinningTeamChange(nr.getWinTeam());
165 | }
166 | if (nr.getPhase() != null && (cr.getPhase() == null || !cr.getPhase().equals(nr.getPhase()))) {
167 | if (nr.getPhase().equals("live"))
168 | handle.roundLive();
169 | else if (nr.getPhase().equals("freezetime"))
170 | handle.roundFreezeTime();
171 | else if (nr.getPhase().equals("over"))
172 | handle.roundOver();
173 | }
174 | }
175 | }
176 | } else {
177 | handle.roundReset();
178 | }
179 | // PLAYER
180 | if (jsr.getPlayer() != null) {
181 | // This can't be right.. I'm just dumb
182 | // Maybe it is right..
183 | if ((serv.onlyUser && jsr.getPlayer().getSteamid().equals(jsr.getProvider().getSteamid())) || !serv.onlyUser) {
184 | handle.receivedPlayer(jsr.getPlayer());
185 | if (currentJSR.getPlayer() == null || !currentJSR.getPlayer().equals(jsr.getPlayer())) {
186 | Player cp = currentJSR.getPlayer();
187 | Player np = jsr.getPlayer();
188 | if (cp == null) {
189 | handle.newPlayer(np);
190 | if (np.getSteamid() != null)
191 | handle.playerSteamIDChange(np.getSteamid());
192 | if (np.getTeam() != null)
193 | handle.playerTeamChange(np.getTeam());
194 | if (np.getActivity() != null)
195 | handle.playerActivityChange(np.getActivity());
196 | if (np.getName() != null)
197 | handle.playerNameChange(np.getName());
198 | if (np.getState() != null) {
199 | handle.playerStateChange(np.getState());
200 | State s = np.getState();
201 | handle.playerHealthChange(s.getHealth());
202 | handle.playerArmorChange(s.getArmor());
203 | handle.playerHelmetChange(s.getHelmet());
204 | handle.playerFlashedChange(s.getFlashed());
205 | handle.playerSmokeChange(s.getSmoked());
206 | handle.playerBurningChange(s.getBurning());
207 | handle.playerMoneyChange(s.getMoney());
208 | handle.playerRoundKillsChange(s.getRoundKills());
209 | handle.playerRoundKillsHSChange(s.getRoundKillhs());
210 | }
211 | if (np.getWeapons() != null) {
212 | handle.newWeapons(np.getWeapons().values().toArray(new Weapon[np.getWeapons().size()]));
213 | handle.weaponsChange(np.getWeapons().values().toArray(new Weapon[np.getWeapons().size()]));
214 | Weapon[] weapons = jsr.getPlayer().getWeapons().values().toArray(new Weapon[jsr.getPlayer().getWeapons().size()]);
215 | for (Weapon w : weapons)
216 | if (w.getState().equals("active")) {
217 | handle.weaponActiveChange(w);
218 | break;
219 | }
220 | }
221 | if (np.getMatchStats() != null) {
222 | MatchStats m = np.getMatchStats();
223 | handle.playerMatchKillsChange(m.getKills());
224 | handle.playerMatchAssistsChange(m.getAssists());
225 | handle.playerMatchDeathsChange(m.getDeaths());
226 | handle.playerMatchMVPSChange(m.getMvps());
227 | handle.playerMatchScoreChange(m.getScore());
228 | }
229 | } else {
230 | if (np.getSteamid() != null && (cp.getSteamid() == null || !cp.getSteamid().equals(np.getSteamid()))) {
231 | handle.playerSteamIDChange(np.getSteamid());
232 | }
233 | if (np.getName() != null && (cp.getName() == null || !cp.getName().equals(np.getName()))) {
234 | handle.playerNameChange(np.getName());
235 | }
236 | if (np.getTeam() != null && (cp.getTeam() == null || !cp.getTeam().equals(np.getTeam()))) {
237 | handle.playerTeamChange(np.getTeam());
238 | }
239 | if (np.getActivity() != null && (cp.getActivity() == null || !cp.getActivity().equals(np.getActivity()))) {
240 | handle.playerActivityChange(np.getActivity());
241 | }
242 | if (np.getState() != null && (cp.getState() == null || !cp.getState().equals(np.getState()))) {
243 | handle.playerStateChange(np.getState());
244 | State ns = np.getState();
245 | State cs = cp.getState();
246 | if (cp.getState() != null) {
247 | if (ns.getHealth() != cs.getHealth())
248 | handle.playerHealthChange(ns.getHealth());
249 | if (ns.getArmor() != cs.getArmor())
250 | handle.playerArmorChange(ns.getArmor());
251 | if (ns.getHelmet() != cs.getHelmet())
252 | handle.playerHelmetChange(ns.getHelmet());
253 | if (ns.getFlashed() != cs.getFlashed())
254 | handle.playerFlashedChange(ns.getFlashed());
255 | if (ns.getSmoked() != cs.getSmoked())
256 | handle.playerSmokeChange(ns.getSmoked());
257 | if (ns.getBurning() != cs.getBurning())
258 | handle.playerBurningChange(ns.getBurning());
259 | if (ns.getMoney() != cs.getMoney())
260 | handle.playerMoneyChange(ns.getMoney());
261 | if (ns.getRoundKills() != cs.getRoundKills())
262 | handle.playerRoundKillsChange(ns.getRoundKillhs());
263 | if (ns.getRoundKillhs() != cs.getRoundKillhs())
264 | handle.playerRoundKillsHSChange(ns.getRoundKillhs());
265 | } else {
266 | handle.playerHealthChange(ns.getHealth());
267 | handle.playerArmorChange(ns.getArmor());
268 | handle.playerHelmetChange(ns.getHelmet());
269 | handle.playerFlashedChange(ns.getFlashed());
270 | handle.playerSmokeChange(ns.getSmoked());
271 | handle.playerBurningChange(ns.getBurning());
272 | handle.playerMoneyChange(ns.getMoney());
273 | handle.playerRoundKillsChange(ns.getRoundKillhs());
274 | handle.playerRoundKillsHSChange(ns.getRoundKillhs());
275 | }
276 | }
277 | // TODO: Weapon Logic
278 | if (np.getWeapons() != null && (cp.getWeapons() == null || !cp.getWeapons().equals(np.getWeapons()))) {
279 | handle.weaponsChange(np.getWeapons().values().toArray(new Weapon[np.getWeapons().size()]));
280 | }
281 | if (np.getMatchStats() != null && (cp.getMatchStats() == null || !cp.getMatchStats().equals(np.getMatchStats()))) {
282 | MatchStats nm = np.getMatchStats();
283 | MatchStats cm = cp.getMatchStats();
284 | handle.playerMatchStatsChange(nm);
285 | if (cm == null) {
286 | handle.playerMatchKillsChange(nm.getKills());
287 | handle.playerMatchAssistsChange(nm.getAssists());
288 | handle.playerMatchDeathsChange(nm.getDeaths());
289 | handle.playerMatchMVPSChange(nm.getMvps());
290 | handle.playerMatchScoreChange(nm.getScore());
291 | } else {
292 | if (nm.getKills() != cm.getKills())
293 | handle.playerMatchKillsChange(nm.getKills());
294 | if (nm.getAssists() != cm.getAssists())
295 | handle.playerMatchAssistsChange(nm.getAssists());
296 | if (nm.getDeaths() != cm.getDeaths())
297 | handle.playerMatchDeathsChange(nm.getDeaths());
298 | if (nm.getMvps() != cm.getMvps())
299 | handle.playerMatchMVPSChange(nm.getMvps());
300 | if (nm.getScore() != cm.getScore())
301 | handle.playerMatchScoreChange(nm.getScore());
302 | }
303 | }
304 | }
305 | }
306 | } else {
307 | jsr.setPlayer(null);
308 | }
309 | } else {
310 | handle.playerReset();
311 | }
312 | // Updates the JSR to the most updated one
313 | // Might not be the correct way of doing... Who knows?
314 | currentJSR = jsr;
315 | } catch (Exception e) {
316 | System.out.println(gson.toJson(jsr));
317 | e.printStackTrace();
318 | }
319 | }
320 |
321 | public JsonResponse getCurrentJSR() {
322 | return currentJSR;
323 | }
324 | }
325 |
--------------------------------------------------------------------------------