Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chat/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (channel *Channel) SendMessage(sender *sessions.User, message string) {
channel.mutex.Lock()
defer channel.mutex.Unlock()

packet := packets.NewServerChatMessage(sender.Info.Id, sender.Info.Username, channel.Name, message)
packet := packets.NewServerChatMessage(sender.Info.Id, sender.Info.Username, sender.Info.ClanTag.String, sender.Info.ClanAccentColor.String, channel.Name, message)

for _, user := range channel.Participants {
if user == sender {
Expand Down
2 changes: 1 addition & 1 deletion chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func AddPrivateMessageHandler(f func(user *sessions.User, receivingUser *session

// Sends a private message to a user
func sendPrivateMessage(sender *sessions.User, receiver *sessions.User, message string) {
sessions.SendPacketToUser(packets.NewServerChatMessage(sender.Info.Id, sender.Info.Username, receiver.Info.Username, message), receiver)
sessions.SendPacketToUser(packets.NewServerChatMessage(sender.Info.Id, sender.Info.Username, sender.Info.ClanTag.String, sender.Info.ClanAccentColor.String, receiver.Info.Username, message), receiver)

err := db.InsertPrivateChatMessage(sender.Info.Id, receiver.Info.Id, receiver.Info.Username, message)

Expand Down
2 changes: 1 addition & 1 deletion db/clans.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetAllClans() ([]*Clan, error) {
func GetClanById(id int) (*Clan, error) {
var clan Clan

err := SQL.Select(&clan, "SELECT id, owner_id, name, tag, customizable FROM clans")
err := SQL.Get(&clan, "SELECT id, owner_id, name, tag, customizable FROM clans WHERE id = ? LIMIT 1", id)

if err != nil && err != sql.ErrNoRows {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions db/multiplayer_match_scores.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ type MultiplayerMatchScore struct {
CountGood int `db:"count_good"`
CountOkay int `db:"count_okay"`
CountMiss int `db:"count_miss"`
CountMineHit int `db:"count_minehit"`
Won int `db:"won"`
}

// InsertIntoDatabase Inserts the score into the database
func (s *MultiplayerMatchScore) InsertIntoDatabase() error {
query := "INSERT INTO multiplayer_match_scores " +
"(user_id, match_id, mods, performance_rating, accuracy, max_combo, count_marv, count_perf, count_great, " +
"count_good, count_okay, count_miss, won, team, score, has_failed, lives_left, full_combo, battle_royale_place) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
"count_good, count_okay, count_miss, count_minehit, won, team, score, has_failed, lives_left, full_combo, battle_royale_place) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

_, err := SQL.Exec(query, s.UserId, s.MatchId, s.Mods, s.PerformanceRating, s.Accuracy, s.MaxCombo, s.CountMarv, s.CountPerf, s.CountGreat,
s.CountGood, s.CountOkay, s.CountMiss, s.Won, 0, 0, 0, 0, 0, 0)
s.CountGood, s.CountOkay, s.CountMiss, s.CountMineHit, s.Won, 0, 0, 0, 0, 0, 0)

if err != nil {
return err
Expand Down
30 changes: 16 additions & 14 deletions db/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import (
)

type User struct {
Id int `db:"id"`
SteamId string `db:"steam_id"`
Username string `db:"username"`
Allowed bool `db:"allowed"`
Privileges common.Privileges `db:"privileges"`
UserGroups common.UserGroups `db:"usergroups"`
MuteEndTime int64 `db:"mute_endtime"`
Country string `db:"country"`
AvatarUrl sql.NullString `db:"avatar_url"`
TwitchUsername sql.NullString `db:"twitch_username"`
ClanId sql.NullInt32 `db:"clan_id"`
Id int `db:"id"`
SteamId string `db:"steam_id"`
Username string `db:"username"`
Allowed bool `db:"allowed"`
Privileges common.Privileges `db:"privileges"`
UserGroups common.UserGroups `db:"usergroups"`
MuteEndTime int64 `db:"mute_endtime"`
Country string `db:"country"`
AvatarUrl sql.NullString `db:"avatar_url"`
TwitchUsername sql.NullString `db:"twitch_username"`
ClanId sql.NullInt32 `db:"clan_id"`
ClanTag sql.NullString `db:"clan_tag"`
ClanAccentColor sql.NullString `db:"clan_accent_color"`
}

// GetProfileUrl Returns the full profile url for the user
Expand All @@ -31,7 +33,7 @@ func (u *User) GetProfileUrl() string {

// GetUserById Retrieves a user from the database by their id
func GetUserById(id int) (*User, error) {
query := "SELECT id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url, twitch_username, clan_id FROM users WHERE id = ? LIMIT 1"
query := "SELECT users.id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url, twitch_username, clan_id, clans.tag AS clan_tag, clans.accent_color AS clan_accent_color FROM users LEFT JOIN clans ON users.clan_id = clans.id WHERE users.id = ? LIMIT 1"

var user User
err := SQL.Get(&user, query, id)
Expand All @@ -45,7 +47,7 @@ func GetUserById(id int) (*User, error) {

// GetUserBySteamId Retrieves a user from the database by their Steam id
func GetUserBySteamId(steamId string) (*User, error) {
query := "SELECT id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url, twitch_username, clan_id FROM users WHERE steam_id = ? LIMIT 1"
query := "SELECT users.id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url, twitch_username, clan_id, clans.tag AS clan_tag, clans.accent_color AS clan_accent_color FROM users LEFT JOIN clans ON users.clan_id = clans.id WHERE steam_id = ? LIMIT 1"

var user User
err := SQL.Get(&user, query, steamId)
Expand All @@ -59,7 +61,7 @@ func GetUserBySteamId(steamId string) (*User, error) {

// GetUserByUsername Rerieves a user from the database by their username
func GetUserByUsername(username string) (*User, error) {
query := "SELECT id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url, twitch_username, clan_id FROM users WHERE username = ? LIMIT 1"
query := "SELECT users.id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url, twitch_username, clan_id, clans.tag AS clan_tag, clans.accent_color AS clan_accent_color FROM users LEFT JOIN clans ON users.clan_id = clans.id WHERE username = ? LIMIT 1"

var user User
err := SQL.Get(&user, query, username)
Expand Down
15 changes: 9 additions & 6 deletions objects/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
)

type PacketUser struct {
Id int `json:"id"`
SteamId string `json:"sid"`
Username string `json:"u"`
UserGroups common.UserGroups `json:"ug"`
MuteEndTime int64 `json:"m"`
Country string `json:"c"`
Id int `json:"id"`
SteamId string `json:"sid"`
Username string `json:"u"`
UserGroups common.UserGroups `json:"ug"`
MuteEndTime int64 `json:"m"`
Country string `json:"c"`
ClanId int `json:"cid,omitempty"`
ClanTag string `json:"ct,omitempty"`
ClanAccentColor string `json:"ca,omitempty"`
}
28 changes: 16 additions & 12 deletions packets/ServerChatMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import "time"

type ServerChatMessage struct {
Packet
SenderId int `json:"sid"`
SenderName string `json:"u"`
To string `json:"to"` // The #channel or player username
Message string `json:"m"`
Time int64 `json:"ts"`
SenderId int `json:"sid"`
SenderName string `json:"u"`
SenderClanTag string `json:"sct"`
SenderClanAccentColor string `json:"sca"`
To string `json:"to"` // The #channel or player username
Message string `json:"m"`
Time int64 `json:"ts"`
}

func NewServerChatMessage(senderId int, senderName string, to string, message string) *ServerChatMessage {
func NewServerChatMessage(senderId int, senderName string, senderClanTag string, senderClanAccentColor string, to string, message string) *ServerChatMessage {
return &ServerChatMessage{
Packet: Packet{Id: PacketIdServerChatMessage},
SenderId: senderId,
SenderName: senderName,
To: to,
Message: message,
Time: time.Now().UnixMilli(),
Packet: Packet{Id: PacketIdServerChatMessage},
SenderId: senderId,
SenderName: senderName,
SenderClanTag: senderClanTag,
SenderClanAccentColor: senderClanAccentColor,
To: to,
Message: message,
Time: time.Now().UnixMilli(),
}
}
15 changes: 9 additions & 6 deletions sessions/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,15 @@ func (u *User) SerializeForPacket() *objects.PacketUser {
defer u.Mutex.Unlock()

return &objects.PacketUser{
Id: u.Info.Id,
SteamId: u.Info.SteamId,
Username: u.Info.Username,
UserGroups: u.Info.UserGroups,
MuteEndTime: u.Info.MuteEndTime,
Country: u.Info.Country,
Id: u.Info.Id,
SteamId: u.Info.SteamId,
Username: u.Info.Username,
UserGroups: u.Info.UserGroups,
MuteEndTime: u.Info.MuteEndTime,
Country: u.Info.Country,
ClanId: int(u.Info.ClanId.Int32),
ClanTag: u.Info.ClanTag.String,
ClanAccentColor: u.Info.ClanAccentColor.String,
}
}

Expand Down
Loading