4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-27 16:59:23 +00:00

Add vendor (steam)

This commit is contained in:
Wim
2017-06-22 01:00:27 +02:00
parent 1f9874102a
commit 1f91461853
117 changed files with 115543 additions and 0 deletions

View File

@ -0,0 +1,111 @@
package socialcache
import (
"errors"
. "github.com/Philipp15b/go-steam/protocol/steamlang"
. "github.com/Philipp15b/go-steam/steamid"
"sync"
)
// Chats list is a thread safe map
// They can be iterated over like so:
// for id, chat := range client.Social.Chats.GetCopy() {
// log.Println(id, chat.Name)
// }
type ChatsList struct {
mutex sync.RWMutex
byId map[SteamId]*Chat
}
// Returns a new chats list
func NewChatsList() *ChatsList {
return &ChatsList{byId: make(map[SteamId]*Chat)}
}
// Adds a chat to the chat list
func (list *ChatsList) Add(chat Chat) {
list.mutex.Lock()
defer list.mutex.Unlock()
_, exists := list.byId[chat.SteamId]
if !exists { //make sure this doesnt already exist
list.byId[chat.SteamId] = &chat
}
}
// Removes a chat from the chat list
func (list *ChatsList) Remove(id SteamId) {
list.mutex.Lock()
defer list.mutex.Unlock()
delete(list.byId, id)
}
// Adds a chat member to a given chat
func (list *ChatsList) AddChatMember(id SteamId, member ChatMember) {
list.mutex.Lock()
defer list.mutex.Unlock()
chat := list.byId[id]
if chat == nil { //Chat doesn't exist
chat = &Chat{SteamId: id}
list.byId[id] = chat
}
if chat.ChatMembers == nil { //New chat
chat.ChatMembers = make(map[SteamId]ChatMember)
}
chat.ChatMembers[member.SteamId] = member
}
// Removes a chat member from a given chat
func (list *ChatsList) RemoveChatMember(id SteamId, member SteamId) {
list.mutex.Lock()
defer list.mutex.Unlock()
chat := list.byId[id]
if chat == nil { //Chat doesn't exist
return
}
if chat.ChatMembers == nil { //New chat
return
}
delete(chat.ChatMembers, member)
}
// Returns a copy of the chats map
func (list *ChatsList) GetCopy() map[SteamId]Chat {
list.mutex.RLock()
defer list.mutex.RUnlock()
glist := make(map[SteamId]Chat)
for key, chat := range list.byId {
glist[key] = *chat
}
return glist
}
// Returns a copy of the chat of a given SteamId
func (list *ChatsList) ById(id SteamId) (Chat, error) {
list.mutex.RLock()
defer list.mutex.RUnlock()
if val, ok := list.byId[id]; ok {
return *val, nil
}
return Chat{}, errors.New("Chat not found")
}
// Returns the number of chats
func (list *ChatsList) Count() int {
list.mutex.RLock()
defer list.mutex.RUnlock()
return len(list.byId)
}
// A Chat
type Chat struct {
SteamId SteamId `json:",string"`
GroupId SteamId `json:",string"`
ChatMembers map[SteamId]ChatMember
}
// A Chat Member
type ChatMember struct {
SteamId SteamId `json:",string"`
ChatPermissions EChatPermission
ClanPermissions EClanPermission
}

View File

@ -0,0 +1,146 @@
package socialcache
import (
"errors"
. "github.com/Philipp15b/go-steam/protocol/steamlang"
. "github.com/Philipp15b/go-steam/steamid"
"sync"
)
// Friends list is a thread safe map
// They can be iterated over like so:
// for id, friend := range client.Social.Friends.GetCopy() {
// log.Println(id, friend.Name)
// }
type FriendsList struct {
mutex sync.RWMutex
byId map[SteamId]*Friend
}
// Returns a new friends list
func NewFriendsList() *FriendsList {
return &FriendsList{byId: make(map[SteamId]*Friend)}
}
// Adds a friend to the friend list
func (list *FriendsList) Add(friend Friend) {
list.mutex.Lock()
defer list.mutex.Unlock()
_, exists := list.byId[friend.SteamId]
if !exists { //make sure this doesnt already exist
list.byId[friend.SteamId] = &friend
}
}
// Removes a friend from the friend list
func (list *FriendsList) Remove(id SteamId) {
list.mutex.Lock()
defer list.mutex.Unlock()
delete(list.byId, id)
}
// Returns a copy of the friends map
func (list *FriendsList) GetCopy() map[SteamId]Friend {
list.mutex.RLock()
defer list.mutex.RUnlock()
flist := make(map[SteamId]Friend)
for key, friend := range list.byId {
flist[key] = *friend
}
return flist
}
// Returns a copy of the friend of a given SteamId
func (list *FriendsList) ById(id SteamId) (Friend, error) {
list.mutex.RLock()
defer list.mutex.RUnlock()
if val, ok := list.byId[id]; ok {
return *val, nil
}
return Friend{}, errors.New("Friend not found")
}
// Returns the number of friends
func (list *FriendsList) Count() int {
list.mutex.RLock()
defer list.mutex.RUnlock()
return len(list.byId)
}
//Setter methods
func (list *FriendsList) SetName(id SteamId, name string) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.Name = name
}
}
func (list *FriendsList) SetAvatar(id SteamId, hash string) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.Avatar = hash
}
}
func (list *FriendsList) SetRelationship(id SteamId, relationship EFriendRelationship) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.Relationship = relationship
}
}
func (list *FriendsList) SetPersonaState(id SteamId, state EPersonaState) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.PersonaState = state
}
}
func (list *FriendsList) SetPersonaStateFlags(id SteamId, flags EPersonaStateFlag) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.PersonaStateFlags = flags
}
}
func (list *FriendsList) SetGameAppId(id SteamId, gameappid uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.GameAppId = gameappid
}
}
func (list *FriendsList) SetGameId(id SteamId, gameid uint64) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.GameId = gameid
}
}
func (list *FriendsList) SetGameName(id SteamId, name string) {
list.mutex.Lock()
defer list.mutex.Unlock()
if val, ok := list.byId[id]; ok {
val.GameName = name
}
}
// A Friend
type Friend struct {
SteamId SteamId `json:",string"`
Name string
Avatar string
Relationship EFriendRelationship
PersonaState EPersonaState
PersonaStateFlags EPersonaStateFlag
GameAppId uint32
GameId uint64 `json:",string"`
GameName string
}

View File

@ -0,0 +1,145 @@
package socialcache
import (
"errors"
. "github.com/Philipp15b/go-steam/protocol/steamlang"
. "github.com/Philipp15b/go-steam/steamid"
"sync"
)
// Groups list is a thread safe map
// They can be iterated over like so:
// for id, group := range client.Social.Groups.GetCopy() {
// log.Println(id, group.Name)
// }
type GroupsList struct {
mutex sync.RWMutex
byId map[SteamId]*Group
}
// Returns a new groups list
func NewGroupsList() *GroupsList {
return &GroupsList{byId: make(map[SteamId]*Group)}
}
// Adds a group to the group list
func (list *GroupsList) Add(group Group) {
list.mutex.Lock()
defer list.mutex.Unlock()
_, exists := list.byId[group.SteamId]
if !exists { //make sure this doesnt already exist
list.byId[group.SteamId] = &group
}
}
// Removes a group from the group list
func (list *GroupsList) Remove(id SteamId) {
list.mutex.Lock()
defer list.mutex.Unlock()
delete(list.byId, id)
}
// Returns a copy of the groups map
func (list *GroupsList) GetCopy() map[SteamId]Group {
list.mutex.RLock()
defer list.mutex.RUnlock()
glist := make(map[SteamId]Group)
for key, group := range list.byId {
glist[key] = *group
}
return glist
}
// Returns a copy of the group of a given SteamId
func (list *GroupsList) ById(id SteamId) (Group, error) {
list.mutex.RLock()
defer list.mutex.RUnlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
return *val, nil
}
return Group{}, errors.New("Group not found")
}
// Returns the number of groups
func (list *GroupsList) Count() int {
list.mutex.RLock()
defer list.mutex.RUnlock()
return len(list.byId)
}
//Setter methods
func (list *GroupsList) SetName(id SteamId, name string) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.Name = name
}
}
func (list *GroupsList) SetAvatar(id SteamId, hash string) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.Avatar = hash
}
}
func (list *GroupsList) SetRelationship(id SteamId, relationship EClanRelationship) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.Relationship = relationship
}
}
func (list *GroupsList) SetMemberTotalCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberTotalCount = count
}
}
func (list *GroupsList) SetMemberOnlineCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberOnlineCount = count
}
}
func (list *GroupsList) SetMemberChattingCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberChattingCount = count
}
}
func (list *GroupsList) SetMemberInGameCount(id SteamId, count uint32) {
list.mutex.Lock()
defer list.mutex.Unlock()
id = id.ChatToClan()
if val, ok := list.byId[id]; ok {
val.MemberInGameCount = count
}
}
// A Group
type Group struct {
SteamId SteamId `json:",string"`
Name string
Avatar string
Relationship EClanRelationship
MemberTotalCount uint32
MemberOnlineCount uint32
MemberChattingCount uint32
MemberInGameCount uint32
}