func sendCmds(conn *network.GameConn, cmd <-chan network.GameMsg) { for { msg := <-cmd err := network.Send(conn, msg) if err != nil { log.Print(err) return } } }
func (client ClientConn) clientSender() { for { resp := <-client.SendChanRead err := network.Send(client.GameConn, resp) if err != nil { log.Print(err) return } } }
func main() { log.SetFlags(log.Lshortfile) // Prompt the user for their name and pass var name, pass, character string fmt.Printf("*** Stuff N' Things the RPG ***\n") fmt.Printf("Login:"******"Password:"******"Logging in as %s\n", name) req := network.GameMsg{LoginReq: &network.LoginReq{Version: 1, Username: name, Password: pass}} //log.Printf("main: %s\n", req); // Connect to the server conn, err := network.Connect("") if err != nil { log.Fatal(err) } // Send the request err = network.Send(conn, req) if err != nil { log.Fatal(err) } resp, msgType, err := network.Recv(conn) if err != nil { log.Fatal(err) } // Did we log in successfully? if msgType == network.TypeResp && resp.Resp.Success == true { fmt.Printf("Login Successful :)\n") } else { fmt.Printf("Login Failed :(\n") fmt.Printf("Server says: %s\n", resp.Resp.Message) os.Exit(1) } // Character select fmt.Printf("Available characters:\n") for index, each := range resp.Resp.Data { fmt.Printf("%d) %s\n", index+1, each) } fmt.Printf("Which character would you like to play? ") fmt.Scanln(&character) req = network.GameMsg{AssumeActorReq: &network.AssumeActorReq{Actor: character}} // Send the request err = network.Send(conn, req) if err != nil { log.Fatal(err) } update := make(chan *network.RoomUpdate) activity := make(chan string) sendChanWrite, sendChanRead := network.NewPipe() go sendCmds(conn, sendChanRead) go recvUpdates(conn, update, activity) // Set up the UI // TODO: make this whole deal an object, add character and other stuff to it as a member startUI(update, activity, sendChanWrite, character) }