@@ -10,58 +10,56 @@ import (
1010 "github.com/gin-gonic/gin"
1111)
1212
13+ // Child of World
14+ type OnlinePlayers struct {
15+ Name string `json:"name"`
16+ Level int `json:"level"`
17+ Vocation string `json:"vocation"`
18+ }
19+
20+ // Child of Worlds
21+ type World struct {
22+ Name string `json:"name"`
23+ Status string `json:"status"` // Status:
24+ PlayersOnline int `json:"players_online"` // Players Online:
25+ RecordPlayers int `json:"record_players"` // Online Record:
26+ RecordDate string `json:"record_date"` // Online Record:
27+ CreationDate string `json:"creation_date"` // Creation Date: -> convert to YYYY-MM
28+ Location string `json:"location"` // Location:
29+ PvpType string `json:"pvp_type"` // PvP Type:
30+ PremiumOnly bool `json:"premium_only"` // Premium Type: premium = true / else: false
31+ TransferType string `json:"transfer_type"` // Transfer Type: regular (if not present) / locked / blocked
32+ WorldsQuestTitles []string `json:"world_quest_titles"` // World Quest Titles:
33+ BattleyeProtected bool `json:"battleye_protected"` // BattlEye Status: true if protected / false if "Not protected by BattlEye."
34+ BattleyeDate string `json:"battleye_date"` // BattlEye Status: null if since release / else show date?
35+ GameWorldType string `json:"game_world_type"` // Game World Type: regular / experimental / tournament (if Tournament World Type exists)
36+ TournamentWorldType string `json:"tournament_world_type"` // Tournament World Type: "" (default?) / regular / restricted
37+ OnlinePlayers []OnlinePlayers `json:"online_players"`
38+ }
39+
40+ // Child of JSONData
41+ type Worlds struct {
42+ World World `json:"world"`
43+ }
44+
45+ //
46+ // The base includes two levels: World and Information
47+ type WorldResponse struct {
48+ Worlds Worlds `json:"worlds"`
49+ Information Information `json:"information"`
50+ }
51+
1352var (
1453 WorldDataRowRegex = regexp .MustCompile (`<td class=.*>(.*):<\/td><td>(.*)<\/td>` )
1554 WorldRecordInformationRegex = regexp .MustCompile (`(.*) players \(on (.*)\)` )
1655 BattlEyeProtectedSinceRegex = regexp .MustCompile (`Protected by BattlEye since (.*)\.` )
1756 OnlinePlayerRegex = regexp .MustCompile (`<td style=.*name=.*">(.*)<\/a>.*">(.*)<\/td>.*">(.*)<\/td>` )
1857)
1958
20- // TibiaWorldsWorldV3 func
2159func TibiaWorldsWorldV3 (c * gin.Context ) {
22-
2360 // getting params from URL
2461 world := c .Param ("world" )
2562
26- // Child of World
27- type OnlinePlayers struct {
28- Name string `json:"name"`
29- Level int `json:"level"`
30- Vocation string `json:"vocation"`
31- }
32-
33- // Child of Worlds
34- type World struct {
35- Name string `json:"name"`
36- Status string `json:"status"` // Status:
37- PlayersOnline int `json:"players_online"` // Players Online:
38- RecordPlayers int `json:"record_players"` // Online Record:
39- RecordDate string `json:"record_date"` // Online Record:
40- CreationDate string `json:"creation_date"` // Creation Date: -> convert to YYYY-MM
41- Location string `json:"location"` // Location:
42- PvpType string `json:"pvp_type"` // PvP Type:
43- PremiumOnly bool `json:"premium_only"` // Premium Type: premium = true / else: false
44- TransferType string `json:"transfer_type"` // Transfer Type: regular (if not present) / locked / blocked
45- WorldsQuestTitles []string `json:"world_quest_titles"` // World Quest Titles:
46- BattleyeProtected bool `json:"battleye_protected"` // BattlEye Status: true if protected / false if "Not protected by BattlEye."
47- BattleyeDate string `json:"battleye_date"` // BattlEye Status: null if since release / else show date?
48- GameWorldType string `json:"game_world_type"` // Game World Type: regular / experimental / tournament (if Tournament World Type exists)
49- TournamentWorldType string `json:"tournament_world_type"` // Tournament World Type: "" (default?) / regular / restricted
50- OnlinePlayers []OnlinePlayers `json:"online_players"`
51- }
52-
53- // Child of JSONData
54- type Worlds struct {
55- World World `json:"world"`
56- }
57-
58- //
59- // The base includes two levels: World and Information
60- type JSONData struct {
61- Worlds Worlds `json:"worlds"`
62- Information Information `json:"information"`
63- }
64-
6563 // Adding fix for First letter to be upper and rest lower
6664 world = TibiadataStringWorldFormatToTitleV3 (world )
6765
@@ -75,6 +73,16 @@ func TibiaWorldsWorldV3(c *gin.Context) {
7573 return
7674 }
7775
76+ worldJson := TibiaWorldsWorldV3Impl (world , BoxContentHTML )
77+
78+ // return jsonData
79+ TibiaDataAPIHandleSuccessResponse (c , "TibiaWorldsWorldV3" , worldJson )
80+ }
81+
82+ // TibiaWorldsWorldV3 func
83+ func TibiaWorldsWorldV3Impl (world string , BoxContentHTML string ) WorldResponse {
84+ //TODO: We need to read the world name from the response rather than pass it into this func
85+
7886 // Loading HTML data into ReaderHTML for goquery with NewReader
7987 ReaderHTML , err := goquery .NewDocumentFromReader (strings .NewReader (BoxContentHTML ))
8088 if err != nil {
@@ -131,7 +139,7 @@ func TibiaWorldsWorldV3(c *gin.Context) {
131139 }
132140 }
133141 if WorldsInformationLeftColumn == "Creation Date" {
134- WorldsCreationDate = WorldsInformationRightColumn
142+ WorldsCreationDate = TibiadataDateV3 ( WorldsInformationRightColumn )
135143 }
136144 if WorldsInformationLeftColumn == "Location" {
137145 WorldsLocation = WorldsInformationRightColumn
@@ -165,7 +173,7 @@ func TibiaWorldsWorldV3(c *gin.Context) {
165173 WorldsBattleyeDate = "release"
166174 } else {
167175 subma21 := BattlEyeProtectedSinceRegex .FindAllStringSubmatch (WorldsInformationRightColumn , - 1 )
168- WorldsBattleyeDate = subma21 [0 ][1 ]
176+ WorldsBattleyeDate = TibiadataDateV3 ( subma21 [0 ][1 ])
169177 }
170178 }
171179 }
@@ -198,16 +206,16 @@ func TibiaWorldsWorldV3(c *gin.Context) {
198206 if len (subma1 ) > 0 {
199207
200208 WorldsOnlinePlayers = append (WorldsOnlinePlayers , OnlinePlayers {
201- Name : subma1 [0 ][1 ],
209+ Name : TibiaDataSanitizeNbspSpaceString ( subma1 [0 ][1 ]) ,
202210 Level : TibiadataStringToIntegerV3 (subma1 [0 ][2 ]),
203- Vocation : subma1 [0 ][3 ],
211+ Vocation : TibiaDataSanitizeNbspSpaceString ( subma1 [0 ][3 ]) ,
204212 })
205213 }
206214 })
207215
208216 //
209217 // Build the data-blob
210- jsonData := JSONData {
218+ return WorldResponse {
211219 Worlds : Worlds {
212220 World {
213221 Name : world ,
@@ -233,7 +241,4 @@ func TibiaWorldsWorldV3(c *gin.Context) {
233241 Timestamp : TibiadataDatetimeV3 ("" ),
234242 },
235243 }
236-
237- // return jsonData
238- TibiaDataAPIHandleSuccessResponse (c , "TibiaWorldsWorldV3" , jsonData )
239244}
0 commit comments