Added more logging to server

This commit is contained in:
qowevisa 2024-06-08 21:45:36 +03:00
parent c5e7f6c545
commit 99dbc74775
3 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"log"
"sync" "sync"
com "git.qowevisa.me/Qowevisa/gotell/communication" com "git.qowevisa.me/Qowevisa/gotell/communication"
@ -34,6 +35,7 @@ func (l *LinkCenter) AddLink(id uint16, link com.Link) error {
LeftNum: link.UseCount, LeftNum: link.UseCount,
UserID: id, UserID: id,
} }
log.Printf("Added link by %s\n", string(link.Data))
l.Mu.Unlock() l.Mu.Unlock()
return nil return nil
} }
@ -46,6 +48,7 @@ func (l *LinkCenter) DeleteLink(data []byte) error {
} }
func (l *LinkCenter) GetLink(data []byte) (*UserLink, error) { func (l *LinkCenter) GetLink(data []byte) (*UserLink, error) {
log.Printf("LinkCenter : GetLink by : %s\n", string(data))
val, found := l.Links[string(data)] val, found := l.Links[string(data)]
if !found { if !found {
return nil, ERROR_DONT_HAVE return nil, ERROR_DONT_HAVE

View File

@ -94,7 +94,7 @@ func handleClient(conn net.Conn) {
if err != nil { if err != nil {
answ, err := com.ServerSendClientDecline() answ, err := com.ServerSendClientDecline()
if err != nil { if err != nil {
log.Printf("ERROR: %v\n", err) log.Printf("ERROR: BYTES: %v\n", err)
continue continue
} }
conn.Write(answ) conn.Write(answ)
@ -103,7 +103,7 @@ func handleClient(conn net.Conn) {
binary.BigEndian.PutUint16(idBytes, id) binary.BigEndian.PutUint16(idBytes, id)
answ, err := com.ServerSendClientHisID(idBytes) answ, err := com.ServerSendClientHisID(idBytes)
if err != nil { if err != nil {
log.Printf("ERROR: %v\n", err) log.Printf("ERROR: BYTES: %v\n", err)
continue continue
} }
conn.Write(answ) conn.Write(answ)
@ -136,7 +136,7 @@ func handleClient(conn net.Conn) {
case com.ID_CLIENT_ASK_SERVER_LINK: case com.ID_CLIENT_ASK_SERVER_LINK:
link, err := linkCenter.GetLink(msg.Data) link, err := linkCenter.GetLink(msg.Data)
if err != nil { if err != nil {
log.Printf("Error: %v\n", err) log.Printf("Error: GetLink: %v\n", err)
continue continue
} }
if link.LeftNum == 0 { if link.LeftNum == 0 {

View File

@ -23,8 +23,8 @@ func (u *UserCenter) Init() {
} }
var ( var (
ERROR_ALREADY_HAVE = errors.New("Username is already taken") ERROR_ALREADY_HAVE = errors.New("Already taken")
ERROR_DONT_HAVE = errors.New("Username was not found") ERROR_DONT_HAVE = errors.New("Not found")
) )
func (u *UserCenter) AddUser(name string) (uint16, error) { func (u *UserCenter) AddUser(name string) (uint16, error) {