"math/rand"
"net"
"os"
+ "strconv"
"strings"
"time"
)
const clientConfigPath = "/usr/local/etc/mobius-client-config.yaml"
+const (
+ trackerListPage = "trackerList"
+)
//go:embed client/banners/*.txt
var bannerDir embed.FS
Username string `yaml:"Username"`
IconID int `yaml:"IconID"`
Bookmarks []Bookmark `yaml:"Bookmarks"`
+ Tracker string `yaml:"Tracker"`
}
func readConfig(cfgPath string) (*ClientPrefs, error) {
app := tview.NewApplication()
chatBox := tview.NewTextView().
SetScrollable(true).
- SetText("").
SetDynamicColors(true).
SetWordWrap(true).
SetChangedFunc(func() {
chatInput.
SetLabel("> ").
SetFieldBackgroundColor(tcell.ColorDimGray).
- //SetFieldTextColor(tcell.ColorWhite).
SetDoneFunc(func(key tcell.Key) {
// skip send if user hit enter with no other text
if len(chatInput.GetText()) == 0 {
chatInput.Box.SetBorder(true).SetTitle("Send")
- userList := tview.NewTextView().SetDynamicColors(true)
- userList.SetChangedFunc(func() {
- app.Draw() // TODO: docs say this is bad but it's the only way to show content during initial render??
- })
+ userList := tview.
+ NewTextView().
+ SetDynamicColors(true).
+ SetChangedFunc(func() {
+ app.Draw() // TODO: docs say this is bad but it's the only way to show content during initial render??
+ })
userList.Box.SetBorder(true).SetTitle("Users")
return &UI{
}
}
-const defaultUsername = "unnamed"
-
-const (
- trackerListPage = "trackerList"
-)
-
func (ui *UI) showBookmarks() *tview.List {
list := tview.NewList()
list.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
}
func (ui *UI) getTrackerList() *tview.List {
- listing, err := GetListing("hltracker.com:5498")
+ listing, err := GetListing(ui.HLClient.pref.Tracker)
if err != nil {
spew.Dump(err)
}
}
func (ui *UI) renderSettingsForm() *tview.Flex {
+ iconStr := strconv.Itoa(ui.HLClient.pref.IconID)
settingsForm := tview.NewForm()
- settingsForm.AddInputField("Your Name", ui.HLClient.pref.Username, 20, nil, nil)
+ settingsForm.AddInputField("Your Name", ui.HLClient.pref.Username, 0, nil, nil)
+ settingsForm.AddInputField("IconID",iconStr, 0, func(idStr string, _ rune) bool {
+ _, err := strconv.Atoi(idStr)
+ return err == nil
+ }, nil)
+ settingsForm.AddInputField("Tracker", ui.HLClient.pref.Tracker, 0, nil, nil)
settingsForm.AddButton("Save", func() {
ui.HLClient.pref.Username = settingsForm.GetFormItem(0).(*tview.InputField).GetText()
+ iconStr = settingsForm.GetFormItem(1).(*tview.InputField).GetText()
+ ui.HLClient.pref.IconID, _ = strconv.Atoi(iconStr)
+ ui.HLClient.pref.Tracker = settingsForm.GetFormItem(2).(*tview.InputField).GetText()
+
out, err := yaml.Marshal(&ui.HLClient.pref)
if err != nil {
// TODO: handle err
rand.Seed(time.Now().UnixNano())
bannerFiles, _ := bannerDir.ReadDir("client/banners")
- file, _ := os.ReadFile("banners/" + bannerFiles[rand.Intn(len(bannerFiles))].Name())
+ file, _ := bannerDir.ReadFile("client/banners/" + bannerFiles[rand.Intn(len(bannerFiles))].Name())
return fmt.Sprintf("\n\n\nWelcome to...\n\n[red::b]%s[-:-:-]\n\n", file)
}
0, 1, true,
)
- joinServerPage := ui.renderJoinServerForm("", GuestAccount, "", "home", false, false)
-
mainMenu.AddItem("Join Server", "", 'j', func() {
+ joinServerPage := ui.renderJoinServerForm("", GuestAccount, "", "home", false, false)
ui.Pages.AddPage("joinServer", joinServerPage, true, true)
}).
AddItem("Bookmarks", "", 'b', func() {
)
}
-//// Agree agrees to the server agreement and sends user info, completing the login sequence
-//func (c *Client) Agree() {
-// c.Send(
-// NewTransaction(
-// tranAgreed, 3,
-// []Field{
-// NewField(fieldUserName, []byte("test")),
-// NewField(fieldUserIconID, *c.Icon),
-// NewField(fieldUserFlags, []byte{0x00, 0x00}),
-// },
-// ),
-// )
-// //
-// //// Block until we receive the agreement reply from the server
-// //_ = c.WaitForTransaction(tranAgreed)
-//}
-
-//func (c *Client) WaitForTransaction(id uint16) Transaction {
-// var trans Transaction
-// for {
-// buf := make([]byte, 1400)
-// readLen, err := c.Connection.Read(buf)
-// if err != nil {
-// panic(err)
-// }
-//
-// transactions := ReadTransactions(buf[:readLen])
-// tran, err := FindTransactions(id, transactions)
-// if err == nil {
-// fmt.Println("returning")
-// return tran
-// }
-// }
-//
-// return trans
-//}
-
-//func (c *Client) Read() error {
-// // Main loop where we wait for and take action on client requests
-// for {
-// buf := make([]byte, 1400)
-// readLen, err := c.Connection.Read(buf)
-// if err != nil {
-// panic(err)
-// }
-// transactions, _, _ := readTransactions(buf[:readLen])
-//
-// for _, t := range transactions {
-// c.HandleTransaction(&t)
-// }
-// }
-//
-// return nil
-//}
-
func (c *Client) Send(t Transaction) error {
requestNum := binary.BigEndian.Uint16(t.Type)
tID := binary.BigEndian.Uint32(t.ID)