Skip to content

Commit

Permalink
Merge pull request #2 from FlowingSPDG/hidden-flag
Browse files Browse the repository at this point in the history
Supported hidden flag "F" (playcast "http://YOUR_GOTV_PLUS" f200)
  • Loading branch information
Shugo Kawamura authored Feb 9, 2020
2 parents fb2aa91 + ec544be commit e34a7d6
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 30 deletions.
3 changes: 3 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
grpc "github.com/FlowingSPDG/gotv-plus-go/server/src/grpc"
"github.com/FlowingSPDG/gotv-plus-go/server/src/handlers"
"github.com/gin-gonic/gin"
"io/ioutil"
"log"
"net/http"
)
Expand All @@ -23,6 +24,8 @@ func init() {
log.Printf("DEBUG MODE : %v\n", *debug)
if *debug == true {
gin.SetMode(gin.ReleaseMode)
} else {
gin.DefaultWriter = ioutil.Discard
}
handlers.InitMatchEngine(*auth, uint32(*delay))
go grpc.StartGRPC(*grpcaddr)
Expand Down
132 changes: 102 additions & 30 deletions server/src/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,54 @@ func SyncHandler(c *gin.Context) {
c.String(http.StatusBadRequest, "Unknown Request")
return
}

t := c.Params.ByName("token")
m, err := Matches.GetMatchByToken(t)
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "NotFound")
return
}
full, err := m.GetFullFrame(m.Fragment)
delayedfull, err := m.GetFullFrame(m.Fragment - Matches.Delay)
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "NotFound")
return
if c.Query("fragment") != "" {
frag, err := strconv.Atoi(c.Query("fragment"))
if err != nil {
c.String(http.StatusBadRequest, "fragment should be int")
return
}
full, err := m.GetFullFrame(m.Fragment)
specifiedfull, err := m.GetFullFrame(uint32(frag))
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "NotFound")
return
}
c.JSON(http.StatusOK, gin.H{
"tick": specifiedfull.Tick,
"rtdelay": time.Since(specifiedfull.At).Seconds(),
"rcvage": time.Since(full.At).Seconds(),
"fragment": frag,
"signup_fragment": m.SignupFragment,
"tps": m.Tps,
"protocol": m.Protocol,
})
} else {
full, err := m.GetFullFrame(m.Fragment)
delayedfull, err := m.GetFullFrame(m.Fragment - Matches.Delay)
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "NotFound")
return
}
c.JSON(http.StatusOK, gin.H{
"tick": full.Tick,
"rtdelay": time.Since(delayedfull.At).Seconds(),
"rcvage": time.Since(full.At).Seconds(),
"fragment": m.Fragment - Matches.Delay,
"signup_fragment": m.SignupFragment,
"tps": m.Tps,
"protocol": m.Protocol,
})
}
c.JSON(http.StatusOK, gin.H{
"tick": full.Tick,
"rtdelay": time.Since(delayedfull.At).Seconds(),
"rcvage": time.Since(full.At).Seconds(),
"fragment": m.Fragment - Matches.Delay,
"signup_fragment": m.SignupFragment,
"tps": m.Tps,
"protocol": m.Protocol,
})
}

// SyncByIDHandler handlers request against /match/:token/sync by ID
Expand All @@ -56,22 +81,46 @@ func SyncByIDHandler(c *gin.Context) {
c.String(http.StatusNotFound, "NotFound")
return
}
full, err := m.GetFullFrame(m.Fragment)
delayedfull, err := m.GetFullFrame(m.Fragment - Matches.Delay)
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "NotFound")
return
if c.Query("fragment") != "" {
frag, err := strconv.Atoi(c.Query("fragment"))
if err != nil {
c.String(http.StatusBadRequest, "fragment should be int")
return
}
full, err := m.GetFullFrame(m.Fragment)
specifiedfull, err := m.GetFullFrame(uint32(frag))
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "NotFound")
return
}
c.JSON(http.StatusOK, gin.H{
"tick": specifiedfull.Tick,
"rtdelay": time.Since(specifiedfull.At).Seconds(),
"rcvage": time.Since(full.At).Seconds(),
"fragment": frag,
"signup_fragment": m.SignupFragment,
"tps": m.Tps,
"protocol": m.Protocol,
})
} else {
full, err := m.GetFullFrame(m.Fragment)
delayedfull, err := m.GetFullFrame(m.Fragment - Matches.Delay)
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "NotFound")
return
}
c.JSON(http.StatusOK, gin.H{
"tick": full.Tick,
"rtdelay": time.Since(delayedfull.At).Seconds(),
"rcvage": time.Since(full.At).Seconds(),
"fragment": m.Fragment - Matches.Delay,
"signup_fragment": m.SignupFragment,
"tps": m.Tps,
"protocol": m.Protocol,
})
}
c.JSON(http.StatusOK, gin.H{
"tick": full.Tick,
"rtdelay": time.Since(delayedfull.At).Seconds(),
"rcvage": time.Since(full.At).Seconds(),
"fragment": m.Fragment - Matches.Delay,
"signup_fragment": m.SignupFragment,
"tps": m.Tps,
"protocol": m.Protocol,
})
}

// GetBodyHandler handles fragment request from CS:GO client
Expand Down Expand Up @@ -158,6 +207,7 @@ func PostBodyByIDHandler(c *gin.Context) {
c.String(http.StatusBadRequest, "fragment,tps,protocol should be float or int")
return
}
log.Printf("Received START Fragment. Register match... Token[%s] Tps[%f] Protocol[%d]\n", t, tps, protocol)
Matches.Register(&Match{
ID: id,
Token: t,
Expand All @@ -175,6 +225,13 @@ func PostBodyByIDHandler(c *gin.Context) {
// Fragment: uint32(fragment),
})
m, err := Matches.GetMatchByToken(t)
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "")
return
}
m.Lock()
defer m.Unlock()
m.Startframe[uint32(fragment)] = &Startframe{
At: time.Now(),
Body: reqBody,
Expand All @@ -187,6 +244,8 @@ func PostBodyByIDHandler(c *gin.Context) {
c.String(http.StatusResetContent, "")
return
}
m.Lock()
defer m.Unlock()
tick, err := strconv.Atoi(c.Query("tick"))
if err != nil {
c.String(http.StatusBadRequest, "tick should be float or int")
Expand All @@ -209,6 +268,8 @@ func PostBodyByIDHandler(c *gin.Context) {
c.String(http.StatusResetContent, "")
return
}
m.Lock()
defer m.Unlock()
endtick, err := strconv.Atoi(c.Query("endtick"))
if err != nil {
c.String(http.StatusBadRequest, "endtick should be float or int")
Expand Down Expand Up @@ -281,6 +342,13 @@ func PostBodyHandler(c *gin.Context) {
// Fragment: uint32(fragment),
})
m, err := Matches.GetMatchByToken(t)
if err != nil {
log.Printf("ERR : %v\n", err)
c.String(http.StatusNotFound, "")
return
}
m.Lock()
defer m.Unlock()
m.Startframe[uint32(fragment)] = &Startframe{
At: time.Now(),
Body: reqBody,
Expand All @@ -293,6 +361,8 @@ func PostBodyHandler(c *gin.Context) {
c.String(http.StatusResetContent, "")
return
}
m.Lock()
defer m.Unlock()
tick, err := strconv.Atoi(c.Query("tick"))
if err != nil {
c.String(http.StatusBadRequest, "tick should be float or int")
Expand All @@ -315,6 +385,8 @@ func PostBodyHandler(c *gin.Context) {
c.String(http.StatusResetContent, "")
return
}
m.Lock()
defer m.Unlock()
endtick, err := strconv.Atoi(c.Query("endtick"))
if err != nil {
c.String(http.StatusBadRequest, "endtick should be float or int")
Expand Down

0 comments on commit e34a7d6

Please sign in to comment.