mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-23 01:57:22 +00:00
Clean old code
This commit is contained in:
parent
907a8b7099
commit
646be2eb9f
1 changed files with 0 additions and 171 deletions
171
main.go
171
main.go
|
|
@ -168,11 +168,6 @@ func ws(w http.ResponseWriter, r *http.Request) {
|
|||
var playerIndex int
|
||||
|
||||
client := NewClient(c, webrtc.NewWebRTC())
|
||||
//&Client{
|
||||
//conn: c,
|
||||
////wsOverlord: createOverlordClient(),
|
||||
//peerconnection: webrtc.NewWebRTC(),
|
||||
//}
|
||||
|
||||
client.syncReceive("initwebrtc", func(req WSPacket) WSPacket {
|
||||
log.Println("Received user SDP")
|
||||
|
|
@ -252,172 +247,6 @@ func ws(w http.ResponseWriter, r *http.Request) {
|
|||
client.listen()
|
||||
}
|
||||
|
||||
//func wsold(w http.ResponseWriter, r *http.Request) {
|
||||
//c, err := upgrader.Upgrade(w, r, nil)
|
||||
//if err != nil {
|
||||
//log.Print("[!] WS upgrade:", err)
|
||||
//return
|
||||
//}
|
||||
//defer c.Close()
|
||||
|
||||
//client := &Client{
|
||||
//ws: c,
|
||||
//wsOverlord: createOverlordClient(),
|
||||
//peerconnection: webrtc.NewWebRTC(),
|
||||
//}
|
||||
|
||||
//if IsOverlord {
|
||||
|
||||
//}
|
||||
|
||||
//log.Println("New ws connection")
|
||||
|
||||
//// streaming game
|
||||
|
||||
//// start new games and webrtc stuff?
|
||||
////isDone := false
|
||||
|
||||
//var gameName string
|
||||
//var roomID string
|
||||
//var playerIndex int
|
||||
|
||||
//for {
|
||||
//c.SetReadDeadline(time.Now().Add(readWait))
|
||||
//mt, message, err := c.ReadMessage()
|
||||
//if err != nil {
|
||||
//log.Println("[!] read:", err)
|
||||
//break
|
||||
//}
|
||||
|
||||
//req := WSPacket{}
|
||||
//res := WSPacket{}
|
||||
|
||||
//err = json.Unmarshal(message, &req)
|
||||
//if err != nil {
|
||||
//log.Println("[!] json unmarshal:", err)
|
||||
//break
|
||||
//}
|
||||
|
||||
//// SDP connection initializations follows WebRTC convention
|
||||
//// https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Protocols
|
||||
//switch req.ID {
|
||||
////case "ping":
|
||||
////gameName = req.Data
|
||||
////roomID = req.RoomID
|
||||
////playerIndex = req.PlayerIndex
|
||||
////log.Println("Ping from server with game:", gameName)
|
||||
////res.ID = "pong"
|
||||
|
||||
//case "initwebrtc":
|
||||
//log.Println("Received user SDP")
|
||||
//localSession, err := client.peerconnection.StartClient(req.Data, width, height)
|
||||
//if err != nil {
|
||||
//log.Fatalln(err)
|
||||
//}
|
||||
|
||||
//res.ID = "sdp"
|
||||
//res.Data = localSession
|
||||
|
||||
//// Master received request Offer
|
||||
////case "requestOffer":
|
||||
//// Master ask the host connecting to master to request offer from browser
|
||||
|
||||
////case "receivedRemoteSDP":
|
||||
////log.Println("Received remote rtc")
|
||||
//// Relay message to overlord, so overlord will send to the correct host
|
||||
//// TODO: Include room to data
|
||||
////res.id = "overlordrelaysdp"
|
||||
////res.Data = req.Data
|
||||
|
||||
////case "receivedRelaySDPFromOverlord":
|
||||
////// initwebrtc
|
||||
////log.Println("Received user SDP")
|
||||
////localSession, err := client.peerconnection.StartClient(req.Data, width, height)
|
||||
////if err != nil {
|
||||
////log.Fatalln(err)
|
||||
////}
|
||||
|
||||
////res.ID = "sdp"
|
||||
////res.Data = localSession
|
||||
|
||||
//case "candidate":
|
||||
//// Unuse code
|
||||
//hi := pionRTC.ICECandidateInit{}
|
||||
//err = json.Unmarshal([]byte(req.Data), &hi)
|
||||
//if err != nil {
|
||||
//log.Println("[!] Cannot parse candidate: ", err)
|
||||
//} else {
|
||||
//// webRTC.AddCandidate(hi)
|
||||
//}
|
||||
//res.ID = "candidate"
|
||||
|
||||
//case "remoteStart":
|
||||
//gameName = req.Data
|
||||
//roomID = req.RoomID
|
||||
//log.Println("Received Remote start", gameName, roomID)
|
||||
|
||||
//roomID = startSession(client.peerconnection, gameName, roomID, playerIndex)
|
||||
//res.ID = "start"
|
||||
//res.RoomID = roomID
|
||||
|
||||
//case "start":
|
||||
//gameName = req.Data
|
||||
//roomID = req.RoomID
|
||||
//playerIndex = req.PlayerIndex
|
||||
////log.Println("Ping from server with game:", gameName)
|
||||
////res.ID = "pong"
|
||||
//log.Println("Starting game")
|
||||
//if overlord.isRemoteRoom(roomID) {
|
||||
//res.ID = "overlordRequestOffer"
|
||||
//} else {
|
||||
//roomID = startSession(client.peerconnnection, gameName, roomID, playerIndex)
|
||||
//}
|
||||
//res.ID = "start"
|
||||
//res.RoomID = roomID
|
||||
|
||||
//case "save":
|
||||
//log.Println("Saving game state")
|
||||
//res.ID = "save"
|
||||
//res.Data = "ok"
|
||||
//if roomID != "" {
|
||||
//err = rooms[roomID].director.SaveGame()
|
||||
//if err != nil {
|
||||
//log.Println("[!] Cannot save game state: ", err)
|
||||
//res.Data = "error"
|
||||
//}
|
||||
//} else {
|
||||
//res.Data = "error"
|
||||
//}
|
||||
|
||||
//case "load":
|
||||
//log.Println("Loading game state")
|
||||
//res.ID = "load"
|
||||
//res.Data = "ok"
|
||||
//if roomID != "" {
|
||||
//err = rooms[roomID].director.LoadGame()
|
||||
//if err != nil {
|
||||
//log.Println("[!] Cannot load game state: ", err)
|
||||
//res.Data = "error"
|
||||
//}
|
||||
//} else {
|
||||
//res.Data = "error"
|
||||
//}
|
||||
//}
|
||||
|
||||
//stRes, err := json.Marshal(res)
|
||||
//if err != nil {
|
||||
//log.Println("json marshal:", err)
|
||||
//}
|
||||
|
||||
//c.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
//if strings.HasPrefix(res.ID, "overlord") {
|
||||
//overlord.ws.WriteMessage(res.Data)
|
||||
//}
|
||||
//c.WriteMessage(res.Data)
|
||||
//err = c.WriteMessage(mt, []byte(stRes))
|
||||
//}
|
||||
//}
|
||||
|
||||
// generateRoomID generate a unique room ID containing 16 digits
|
||||
func generateRoomID() string {
|
||||
roomID := strconv.FormatInt(rand.Int63(), 16)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue