Updated to latest GTK2 bindings API and moved to Gitlab.
This commit is contained in:
parent
070aa50762
commit
127e1b8ab9
50
cache/cache_object.go
vendored
50
cache/cache_object.go
vendored
@ -10,41 +10,41 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"fmt"
|
||||
"sync"
|
||||
// stdlib
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/cachemodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/cachemodels"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
// Profiles cache.
|
||||
Profiles map[string]*cachemodels.Profile
|
||||
// Profiles cache mutex.
|
||||
ProfilesMutex sync.Mutex
|
||||
// Servers cache.
|
||||
Servers map[string]*cachemodels.Server
|
||||
// Servers cache mutex.
|
||||
ServersMutex sync.Mutex
|
||||
// Profiles cache.
|
||||
Profiles map[string]*cachemodels.Profile
|
||||
// Profiles cache mutex.
|
||||
ProfilesMutex sync.Mutex
|
||||
// Servers cache.
|
||||
Servers map[string]*cachemodels.Server
|
||||
// Servers cache mutex.
|
||||
ServersMutex sync.Mutex
|
||||
}
|
||||
|
||||
func (c *Cache) Initialize() {
|
||||
fmt.Println("Initializing cache...")
|
||||
c.initializeStorages()
|
||||
c.LoadServers(map[string]string{})
|
||||
fmt.Println("Initializing cache...")
|
||||
c.initializeStorages()
|
||||
c.LoadServers(map[string]string{})
|
||||
|
||||
Eventer.AddEventHandler("deleteProfile", c.deleteProfile)
|
||||
Eventer.AddEventHandler("flushProfiles", c.FlushProfiles)
|
||||
Eventer.AddEventHandler("loadProfiles", c.LoadProfiles)
|
||||
Eventer.AddEventHandler("deleteProfile", c.deleteProfile)
|
||||
Eventer.AddEventHandler("flushProfiles", c.FlushProfiles)
|
||||
Eventer.AddEventHandler("loadProfiles", c.LoadProfiles)
|
||||
|
||||
Eventer.AddEventHandler("flushServers", c.FlushServers)
|
||||
Eventer.AddEventHandler("loadServersIntoCache", c.LoadServers)
|
||||
Eventer.AddEventHandler("flushServers", c.FlushServers)
|
||||
Eventer.AddEventHandler("loadServersIntoCache", c.LoadServers)
|
||||
}
|
||||
|
||||
func (c *Cache) initializeStorages() {
|
||||
// Profiles cache.
|
||||
c.Profiles = make(map[string]*cachemodels.Profile)
|
||||
// Servers cache.
|
||||
c.Servers = make(map[string]*cachemodels.Server)
|
||||
// Profiles cache.
|
||||
c.Profiles = make(map[string]*cachemodels.Profile)
|
||||
// Servers cache.
|
||||
c.Servers = make(map[string]*cachemodels.Server)
|
||||
}
|
||||
|
154
cache/cache_profiles.go
vendored
154
cache/cache_profiles.go
vendored
@ -10,105 +10,105 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"fmt"
|
||||
"strconv"
|
||||
// stdlib
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/cachemodels"
|
||||
"github.com/pztrn/urtrator/datamodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/cachemodels"
|
||||
"gitlab.com/pztrn/urtrator/datamodels"
|
||||
)
|
||||
|
||||
func (c *Cache) CreateProfile(name string) {
|
||||
fmt.Println("Creating profile " + name)
|
||||
_, ok := c.Profiles[name]
|
||||
fmt.Println("Creating profile " + name)
|
||||
_, ok := c.Profiles[name]
|
||||
|
||||
if !ok {
|
||||
c.ProfilesMutex.Lock()
|
||||
c.Profiles[name] = &cachemodels.Profile{}
|
||||
c.Profiles[name].Profile = &datamodels.Profile{}
|
||||
c.ProfilesMutex.Unlock()
|
||||
}
|
||||
if !ok {
|
||||
c.ProfilesMutex.Lock()
|
||||
c.Profiles[name] = &cachemodels.Profile{}
|
||||
c.Profiles[name].Profile = &datamodels.Profile{}
|
||||
c.ProfilesMutex.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) deleteProfile(data map[string]string) {
|
||||
fmt.Println("Deleting profile " + data["profile_name"])
|
||||
fmt.Println("Deleting profile " + data["profile_name"])
|
||||
|
||||
c.ProfilesMutex.Lock()
|
||||
_, ok := c.Profiles[data["profile_name"]]
|
||||
c.ProfilesMutex.Unlock()
|
||||
if ok {
|
||||
c.ProfilesMutex.Lock()
|
||||
delete(c.Profiles, data["profile_name"])
|
||||
c.ProfilesMutex.Unlock()
|
||||
}
|
||||
c.ProfilesMutex.Lock()
|
||||
_, ok := c.Profiles[data["profile_name"]]
|
||||
c.ProfilesMutex.Unlock()
|
||||
if ok {
|
||||
c.ProfilesMutex.Lock()
|
||||
delete(c.Profiles, data["profile_name"])
|
||||
c.ProfilesMutex.Unlock()
|
||||
}
|
||||
|
||||
c.ProfilesMutex.Lock()
|
||||
_, ok1 := c.Profiles[data["profile_name"]]
|
||||
c.ProfilesMutex.Unlock()
|
||||
if !ok1 {
|
||||
Database.Db.MustExec(Database.Db.Rebind("DELETE FROM urt_profiles WHERE name=?"), data["profile_name"])
|
||||
fmt.Println("Profile deleted")
|
||||
} else {
|
||||
fmt.Println("Something goes wrong! Profile is still here!")
|
||||
}
|
||||
c.ProfilesMutex.Lock()
|
||||
_, ok1 := c.Profiles[data["profile_name"]]
|
||||
c.ProfilesMutex.Unlock()
|
||||
if !ok1 {
|
||||
Database.Db.MustExec(Database.Db.Rebind("DELETE FROM urt_profiles WHERE name=?"), data["profile_name"])
|
||||
fmt.Println("Profile deleted")
|
||||
} else {
|
||||
fmt.Println("Something goes wrong! Profile is still here!")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) FlushProfiles(data map[string]string) {
|
||||
fmt.Println("Flushing profiles to database...")
|
||||
fmt.Println("Flushing profiles to database...")
|
||||
|
||||
raw_profiles := []datamodels.Profile{}
|
||||
err := Database.Db.Select(&raw_profiles, "SELECT * FROM urt_profiles")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
raw_profiles := []datamodels.Profile{}
|
||||
err := Database.Db.Select(&raw_profiles, "SELECT * FROM urt_profiles")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
cached_profiles := make(map[string]*datamodels.Profile)
|
||||
for i := range raw_profiles {
|
||||
cached_profiles[raw_profiles[i].Name] = c.Profiles[raw_profiles[i].Name].Profile
|
||||
}
|
||||
cached_profiles := make(map[string]*datamodels.Profile)
|
||||
for i := range raw_profiles {
|
||||
cached_profiles[raw_profiles[i].Name] = c.Profiles[raw_profiles[i].Name].Profile
|
||||
}
|
||||
|
||||
new_profiles := make(map[string]*datamodels.Profile)
|
||||
new_profiles := make(map[string]*datamodels.Profile)
|
||||
|
||||
c.ProfilesMutex.Lock()
|
||||
for _, profile := range c.Profiles {
|
||||
_, ok := cached_profiles[profile.Profile.Name]
|
||||
if !ok {
|
||||
fmt.Println("Flushing new profile " + profile.Profile.Name)
|
||||
new_profiles[profile.Profile.Name] = profile.Profile
|
||||
}
|
||||
}
|
||||
c.ProfilesMutex.Unlock()
|
||||
c.ProfilesMutex.Lock()
|
||||
for _, profile := range c.Profiles {
|
||||
_, ok := cached_profiles[profile.Profile.Name]
|
||||
if !ok {
|
||||
fmt.Println("Flushing new profile " + profile.Profile.Name)
|
||||
new_profiles[profile.Profile.Name] = profile.Profile
|
||||
}
|
||||
}
|
||||
c.ProfilesMutex.Unlock()
|
||||
|
||||
tx := Database.Db.MustBegin()
|
||||
fmt.Println("Adding new profiles...")
|
||||
for _, profile := range new_profiles {
|
||||
tx.NamedExec("INSERT INTO urt_profiles (name, version, binary, second_x_session, additional_parameters, profile_path) VALUES (:name, :version, :binary, :second_x_session, :additional_parameters, :profile_path)", &profile)
|
||||
}
|
||||
fmt.Println("Updating existing profiles...")
|
||||
for _, profile := range cached_profiles {
|
||||
fmt.Println(fmt.Sprintf("%+v", profile))
|
||||
tx.NamedExec("UPDATE urt_profiles SET name=:name, version=:version, binary=:binary, second_x_session=:second_x_session, additional_parameters=:additional_parameters, profile_path=:profile_path WHERE name=:name", &profile)
|
||||
}
|
||||
tx.Commit()
|
||||
fmt.Println("Done")
|
||||
tx := Database.Db.MustBegin()
|
||||
fmt.Println("Adding new profiles...")
|
||||
for _, profile := range new_profiles {
|
||||
tx.NamedExec("INSERT INTO urt_profiles (name, version, binary, second_x_session, additional_parameters, profile_path) VALUES (:name, :version, :binary, :second_x_session, :additional_parameters, :profile_path)", &profile)
|
||||
}
|
||||
fmt.Println("Updating existing profiles...")
|
||||
for _, profile := range cached_profiles {
|
||||
fmt.Println(fmt.Sprintf("%+v", profile))
|
||||
tx.NamedExec("UPDATE urt_profiles SET name=:name, version=:version, binary=:binary, second_x_session=:second_x_session, additional_parameters=:additional_parameters, profile_path=:profile_path WHERE name=:name", &profile)
|
||||
}
|
||||
tx.Commit()
|
||||
fmt.Println("Done")
|
||||
}
|
||||
|
||||
func (c *Cache) LoadProfiles(data map[string]string) {
|
||||
fmt.Println("Loading profiles to cache...")
|
||||
fmt.Println("Loading profiles to cache...")
|
||||
|
||||
raw_profiles := []datamodels.Profile{}
|
||||
err := Database.Db.Select(&raw_profiles, "SELECT * FROM urt_profiles")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
raw_profiles := []datamodels.Profile{}
|
||||
err := Database.Db.Select(&raw_profiles, "SELECT * FROM urt_profiles")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
c.ProfilesMutex.Lock()
|
||||
for _, profile := range raw_profiles {
|
||||
c.Profiles[profile.Name] = &cachemodels.Profile{}
|
||||
c.Profiles[profile.Name].Profile = &profile
|
||||
}
|
||||
c.ProfilesMutex.Unlock()
|
||||
c.ProfilesMutex.Lock()
|
||||
for _, profile := range raw_profiles {
|
||||
c.Profiles[profile.Name] = &cachemodels.Profile{}
|
||||
c.Profiles[profile.Name].Profile = &profile
|
||||
}
|
||||
c.ProfilesMutex.Unlock()
|
||||
|
||||
fmt.Println("Load completed. Loaded " + strconv.Itoa(len(c.Profiles)) + " profiles.")
|
||||
fmt.Println("Load completed. Loaded " + strconv.Itoa(len(c.Profiles)) + " profiles.")
|
||||
}
|
||||
|
228
cache/cache_servers.go
vendored
228
cache/cache_servers.go
vendored
@ -10,135 +10,135 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"fmt"
|
||||
// stdlib
|
||||
"fmt"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/cachemodels"
|
||||
"github.com/pztrn/urtrator/datamodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/cachemodels"
|
||||
"gitlab.com/pztrn/urtrator/datamodels"
|
||||
)
|
||||
|
||||
func (c *Cache) CreateServer(addr string) {
|
||||
_, ok := c.Servers[addr]
|
||||
if !ok {
|
||||
c.ServersMutex.Lock()
|
||||
c.Servers[addr] = &cachemodels.Server{}
|
||||
c.Servers[addr].Server = &datamodels.Server{}
|
||||
c.ServersMutex.Unlock()
|
||||
} else {
|
||||
fmt.Println("Server " + addr + " already exist.")
|
||||
}
|
||||
_, ok := c.Servers[addr]
|
||||
if !ok {
|
||||
c.ServersMutex.Lock()
|
||||
c.Servers[addr] = &cachemodels.Server{}
|
||||
c.Servers[addr].Server = &datamodels.Server{}
|
||||
c.ServersMutex.Unlock()
|
||||
} else {
|
||||
fmt.Println("Server " + addr + " already exist.")
|
||||
}
|
||||
}
|
||||
|
||||
// Flush servers to database.
|
||||
func (c *Cache) FlushServers(data map[string]string) {
|
||||
fmt.Println("Updating servers information in database...")
|
||||
raw_cached := []datamodels.Server{}
|
||||
Database.Db.Select(&raw_cached, "SELECT * FROM servers")
|
||||
fmt.Println("Updating servers information in database...")
|
||||
raw_cached := []datamodels.Server{}
|
||||
Database.Db.Select(&raw_cached, "SELECT * FROM servers")
|
||||
|
||||
// Create map[string]*datamodels.Server once, so we won't iterate
|
||||
// over slice of datamodels.Server everytime.
|
||||
cached_servers := make(map[string]*datamodels.Server)
|
||||
for s := range raw_cached {
|
||||
mapping_item_name := raw_cached[s].Ip + ":" + raw_cached[s].Port
|
||||
cached_servers[mapping_item_name] = &raw_cached[s]
|
||||
}
|
||||
// Create map[string]*datamodels.Server once, so we won't iterate
|
||||
// over slice of datamodels.Server everytime.
|
||||
cached_servers := make(map[string]*datamodels.Server)
|
||||
for s := range raw_cached {
|
||||
mapping_item_name := raw_cached[s].Ip + ":" + raw_cached[s].Port
|
||||
cached_servers[mapping_item_name] = &raw_cached[s]
|
||||
}
|
||||
|
||||
new_servers := make(map[string]*datamodels.Server)
|
||||
new_servers := make(map[string]*datamodels.Server)
|
||||
|
||||
// Update our cached mapping.
|
||||
for _, s := range c.Servers {
|
||||
mapping_item_name := s.Server.Ip + ":" + s.Server.Port
|
||||
_, ok := cached_servers[mapping_item_name]
|
||||
if !ok {
|
||||
fmt.Println(mapping_item_name + " not found!")
|
||||
new_servers[mapping_item_name] = &datamodels.Server{}
|
||||
new_servers[mapping_item_name].Ip = s.Server.Ip
|
||||
new_servers[mapping_item_name].Port = s.Server.Port
|
||||
new_servers[mapping_item_name].Name = s.Server.Name
|
||||
new_servers[mapping_item_name].Players = s.Server.Players
|
||||
new_servers[mapping_item_name].Bots = s.Server.Bots
|
||||
new_servers[mapping_item_name].Maxplayers = s.Server.Maxplayers
|
||||
new_servers[mapping_item_name].Ping = s.Server.Ping
|
||||
new_servers[mapping_item_name].Map = s.Server.Map
|
||||
new_servers[mapping_item_name].Gamemode = s.Server.Gamemode
|
||||
new_servers[mapping_item_name].Version = s.Server.Version
|
||||
new_servers[mapping_item_name].ExtendedConfig = s.Server.ExtendedConfig
|
||||
new_servers[mapping_item_name].PlayersInfo = s.Server.PlayersInfo
|
||||
new_servers[mapping_item_name].IsPrivate = s.Server.IsPrivate
|
||||
new_servers[mapping_item_name].Favorite = s.Server.Favorite
|
||||
new_servers[mapping_item_name].ProfileToUse = s.Server.ProfileToUse
|
||||
new_servers[mapping_item_name].Password = s.Server.Password
|
||||
} else {
|
||||
cached_servers[mapping_item_name].Ip = s.Server.Ip
|
||||
cached_servers[mapping_item_name].Port = s.Server.Port
|
||||
cached_servers[mapping_item_name].Name = s.Server.Name
|
||||
cached_servers[mapping_item_name].Players = s.Server.Players
|
||||
cached_servers[mapping_item_name].Bots = s.Server.Bots
|
||||
cached_servers[mapping_item_name].Maxplayers = s.Server.Maxplayers
|
||||
cached_servers[mapping_item_name].Ping = s.Server.Ping
|
||||
cached_servers[mapping_item_name].Map = s.Server.Map
|
||||
cached_servers[mapping_item_name].Gamemode = s.Server.Gamemode
|
||||
cached_servers[mapping_item_name].Version = s.Server.Version
|
||||
cached_servers[mapping_item_name].ExtendedConfig = s.Server.ExtendedConfig
|
||||
cached_servers[mapping_item_name].PlayersInfo = s.Server.PlayersInfo
|
||||
cached_servers[mapping_item_name].IsPrivate = s.Server.IsPrivate
|
||||
cached_servers[mapping_item_name].Favorite = s.Server.Favorite
|
||||
cached_servers[mapping_item_name].ProfileToUse = s.Server.ProfileToUse
|
||||
cached_servers[mapping_item_name].Password = s.Server.Password
|
||||
}
|
||||
}
|
||||
// Update our cached mapping.
|
||||
for _, s := range c.Servers {
|
||||
mapping_item_name := s.Server.Ip + ":" + s.Server.Port
|
||||
_, ok := cached_servers[mapping_item_name]
|
||||
if !ok {
|
||||
fmt.Println(mapping_item_name + " not found!")
|
||||
new_servers[mapping_item_name] = &datamodels.Server{}
|
||||
new_servers[mapping_item_name].Ip = s.Server.Ip
|
||||
new_servers[mapping_item_name].Port = s.Server.Port
|
||||
new_servers[mapping_item_name].Name = s.Server.Name
|
||||
new_servers[mapping_item_name].Players = s.Server.Players
|
||||
new_servers[mapping_item_name].Bots = s.Server.Bots
|
||||
new_servers[mapping_item_name].Maxplayers = s.Server.Maxplayers
|
||||
new_servers[mapping_item_name].Ping = s.Server.Ping
|
||||
new_servers[mapping_item_name].Map = s.Server.Map
|
||||
new_servers[mapping_item_name].Gamemode = s.Server.Gamemode
|
||||
new_servers[mapping_item_name].Version = s.Server.Version
|
||||
new_servers[mapping_item_name].ExtendedConfig = s.Server.ExtendedConfig
|
||||
new_servers[mapping_item_name].PlayersInfo = s.Server.PlayersInfo
|
||||
new_servers[mapping_item_name].IsPrivate = s.Server.IsPrivate
|
||||
new_servers[mapping_item_name].Favorite = s.Server.Favorite
|
||||
new_servers[mapping_item_name].ProfileToUse = s.Server.ProfileToUse
|
||||
new_servers[mapping_item_name].Password = s.Server.Password
|
||||
} else {
|
||||
cached_servers[mapping_item_name].Ip = s.Server.Ip
|
||||
cached_servers[mapping_item_name].Port = s.Server.Port
|
||||
cached_servers[mapping_item_name].Name = s.Server.Name
|
||||
cached_servers[mapping_item_name].Players = s.Server.Players
|
||||
cached_servers[mapping_item_name].Bots = s.Server.Bots
|
||||
cached_servers[mapping_item_name].Maxplayers = s.Server.Maxplayers
|
||||
cached_servers[mapping_item_name].Ping = s.Server.Ping
|
||||
cached_servers[mapping_item_name].Map = s.Server.Map
|
||||
cached_servers[mapping_item_name].Gamemode = s.Server.Gamemode
|
||||
cached_servers[mapping_item_name].Version = s.Server.Version
|
||||
cached_servers[mapping_item_name].ExtendedConfig = s.Server.ExtendedConfig
|
||||
cached_servers[mapping_item_name].PlayersInfo = s.Server.PlayersInfo
|
||||
cached_servers[mapping_item_name].IsPrivate = s.Server.IsPrivate
|
||||
cached_servers[mapping_item_name].Favorite = s.Server.Favorite
|
||||
cached_servers[mapping_item_name].ProfileToUse = s.Server.ProfileToUse
|
||||
cached_servers[mapping_item_name].Password = s.Server.Password
|
||||
}
|
||||
}
|
||||
|
||||
tx := Database.Db.MustBegin()
|
||||
fmt.Println("Adding new servers...")
|
||||
if len(new_servers) > 0 {
|
||||
for _, srv := range new_servers {
|
||||
tx.NamedExec("INSERT INTO servers (ip, port, name, ping, players, maxplayers, gamemode, map, version, extended_config, players_info, is_private, favorite, profile_to_use, bots) VALUES (:ip, :port, :name, :ping, :players, :maxplayers, :gamemode, :map, :version, :extended_config, :players_info, :is_private, :favorite, :profile_to_use, :bots)", srv)
|
||||
}
|
||||
}
|
||||
fmt.Println("Updating cached servers...")
|
||||
for _, srv := range cached_servers {
|
||||
_, err := tx.NamedExec("UPDATE servers SET name=:name, players=:players, maxplayers=:maxplayers, gamemode=:gamemode, map=:map, ping=:ping, version=:version, extended_config=:extended_config, favorite=:favorite, password=:password, players_info=:players_info, is_private=:is_private, profile_to_use=:profile_to_use, bots=:bots WHERE ip=:ip AND port=:port", &srv)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
tx := Database.Db.MustBegin()
|
||||
fmt.Println("Adding new servers...")
|
||||
if len(new_servers) > 0 {
|
||||
for _, srv := range new_servers {
|
||||
tx.NamedExec("INSERT INTO servers (ip, port, name, ping, players, maxplayers, gamemode, map, version, extended_config, players_info, is_private, favorite, profile_to_use, bots) VALUES (:ip, :port, :name, :ping, :players, :maxplayers, :gamemode, :map, :version, :extended_config, :players_info, :is_private, :favorite, :profile_to_use, :bots)", srv)
|
||||
}
|
||||
}
|
||||
fmt.Println("Updating cached servers...")
|
||||
for _, srv := range cached_servers {
|
||||
_, err := tx.NamedExec("UPDATE servers SET name=:name, players=:players, maxplayers=:maxplayers, gamemode=:gamemode, map=:map, ping=:ping, version=:version, extended_config=:extended_config, favorite=:favorite, password=:password, players_info=:players_info, is_private=:is_private, profile_to_use=:profile_to_use, bots=:bots WHERE ip=:ip AND port=:port", &srv)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
fmt.Println("Done")
|
||||
tx.Commit()
|
||||
fmt.Println("Done")
|
||||
}
|
||||
|
||||
func (c *Cache) LoadServers(data map[string]string) {
|
||||
fmt.Println("Loading servers into cache...")
|
||||
c.Servers = make(map[string]*cachemodels.Server)
|
||||
// Getting servers from database.
|
||||
raw_servers := []datamodels.Server{}
|
||||
err := Database.Db.Select(&raw_servers, "SELECT * FROM servers")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
fmt.Println("Loading servers into cache...")
|
||||
c.Servers = make(map[string]*cachemodels.Server)
|
||||
// Getting servers from database.
|
||||
raw_servers := []datamodels.Server{}
|
||||
err := Database.Db.Select(&raw_servers, "SELECT * FROM servers")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
// Due to nature of pointers and goroutines thing (?) this should
|
||||
// be done in this way.
|
||||
for _, server := range raw_servers {
|
||||
key := server.Ip + ":" + server.Port
|
||||
c.CreateServer(key)
|
||||
c.Servers[key].Server.Name = server.Name
|
||||
c.Servers[key].Server.Ip = server.Ip
|
||||
c.Servers[key].Server.Port = server.Port
|
||||
c.Servers[key].Server.Players = server.Players
|
||||
c.Servers[key].Server.Bots = server.Bots
|
||||
c.Servers[key].Server.Maxplayers = server.Maxplayers
|
||||
c.Servers[key].Server.Ping = server.Ping
|
||||
c.Servers[key].Server.Gamemode = server.Gamemode
|
||||
c.Servers[key].Server.Map = server.Map
|
||||
c.Servers[key].Server.Version = server.Version
|
||||
c.Servers[key].Server.Favorite = server.Favorite
|
||||
c.Servers[key].Server.Password = server.Password
|
||||
c.Servers[key].Server.ProfileToUse = server.ProfileToUse
|
||||
c.Servers[key].Server.ExtendedConfig = server.ExtendedConfig
|
||||
c.Servers[key].Server.PlayersInfo = server.PlayersInfo
|
||||
c.Servers[key].Server.IsPrivate = server.IsPrivate
|
||||
}
|
||||
fmt.Println("Load completed.")
|
||||
// Due to nature of pointers and goroutines thing (?) this should
|
||||
// be done in this way.
|
||||
for _, server := range raw_servers {
|
||||
key := server.Ip + ":" + server.Port
|
||||
c.CreateServer(key)
|
||||
c.Servers[key].Server.Name = server.Name
|
||||
c.Servers[key].Server.Ip = server.Ip
|
||||
c.Servers[key].Server.Port = server.Port
|
||||
c.Servers[key].Server.Players = server.Players
|
||||
c.Servers[key].Server.Bots = server.Bots
|
||||
c.Servers[key].Server.Maxplayers = server.Maxplayers
|
||||
c.Servers[key].Server.Ping = server.Ping
|
||||
c.Servers[key].Server.Gamemode = server.Gamemode
|
||||
c.Servers[key].Server.Map = server.Map
|
||||
c.Servers[key].Server.Version = server.Version
|
||||
c.Servers[key].Server.Favorite = server.Favorite
|
||||
c.Servers[key].Server.Password = server.Password
|
||||
c.Servers[key].Server.ProfileToUse = server.ProfileToUse
|
||||
c.Servers[key].Server.ExtendedConfig = server.ExtendedConfig
|
||||
c.Servers[key].Server.PlayersInfo = server.PlayersInfo
|
||||
c.Servers[key].Server.IsPrivate = server.IsPrivate
|
||||
}
|
||||
fmt.Println("Load completed.")
|
||||
}
|
||||
|
18
cache/exported.go
vendored
18
cache/exported.go
vendored
@ -10,19 +10,19 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
// local
|
||||
event "github.com/pztrn/urtrator/eventer"
|
||||
"github.com/pztrn/urtrator/database"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/database"
|
||||
event "gitlab.com/pztrn/urtrator/eventer"
|
||||
)
|
||||
|
||||
var (
|
||||
Database *database.Database
|
||||
Eventer *event.Eventer
|
||||
Database *database.Database
|
||||
Eventer *event.Eventer
|
||||
)
|
||||
|
||||
func New(d *database.Database, e *event.Eventer) *Cache {
|
||||
Database = d
|
||||
Eventer = e
|
||||
c := Cache{}
|
||||
return &c
|
||||
Database = d
|
||||
Eventer = e
|
||||
c := Cache{}
|
||||
return &c
|
||||
}
|
||||
|
@ -10,10 +10,10 @@
|
||||
package cachemodels
|
||||
|
||||
import (
|
||||
// local
|
||||
"github.com/pztrn/urtrator/datamodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/datamodels"
|
||||
)
|
||||
|
||||
type Profile struct {
|
||||
Profile *datamodels.Profile
|
||||
Profile *datamodels.Profile
|
||||
}
|
||||
|
@ -10,20 +10,20 @@
|
||||
package cachemodels
|
||||
|
||||
import (
|
||||
// local
|
||||
"github.com/pztrn/urtrator/datamodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/datamodels"
|
||||
|
||||
// Other
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
// Other
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Server *datamodels.Server
|
||||
AllServersIter *gtk.TreeIter
|
||||
AllServersIterSet bool
|
||||
AllServersIterInList bool
|
||||
Server *datamodels.Server
|
||||
AllServersIter *gtk.TreeIter
|
||||
AllServersIterSet bool
|
||||
AllServersIterInList bool
|
||||
|
||||
FavServersIter *gtk.TreeIter
|
||||
FavServersIterSet bool
|
||||
FavServersIterInList bool
|
||||
FavServersIter *gtk.TreeIter
|
||||
FavServersIterSet bool
|
||||
FavServersIterInList bool
|
||||
}
|
||||
|
@ -9,20 +9,20 @@
|
||||
// ToDo: put full text of license here.
|
||||
package clipboardwatcher
|
||||
|
||||
import(
|
||||
// local
|
||||
"github.com/pztrn/urtrator/cache"
|
||||
"github.com/pztrn/urtrator/eventer"
|
||||
import (
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/cache"
|
||||
"gitlab.com/pztrn/urtrator/eventer"
|
||||
)
|
||||
|
||||
var (
|
||||
Cache *cache.Cache
|
||||
Eventer *eventer.Eventer
|
||||
Cache *cache.Cache
|
||||
Eventer *eventer.Eventer
|
||||
)
|
||||
|
||||
func New(c *cache.Cache, e *eventer.Eventer) *ClipboardWatcher {
|
||||
Cache = c
|
||||
Eventer = e
|
||||
cw := ClipboardWatcher{}
|
||||
return &cw
|
||||
Cache = c
|
||||
Eventer = e
|
||||
cw := ClipboardWatcher{}
|
||||
return &cw
|
||||
}
|
||||
|
@ -10,125 +10,125 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"errors"
|
||||
"fmt"
|
||||
// stdlib
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/cache"
|
||||
"github.com/pztrn/urtrator/clipboardwatcher"
|
||||
"github.com/pztrn/urtrator/colorizer"
|
||||
"github.com/pztrn/urtrator/configuration"
|
||||
"github.com/pztrn/urtrator/database"
|
||||
"github.com/pztrn/urtrator/eventer"
|
||||
"github.com/pztrn/urtrator/launcher"
|
||||
"github.com/pztrn/urtrator/requester"
|
||||
"github.com/pztrn/urtrator/timer"
|
||||
"github.com/pztrn/urtrator/translator"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/cache"
|
||||
"gitlab.com/pztrn/urtrator/clipboardwatcher"
|
||||
"gitlab.com/pztrn/urtrator/colorizer"
|
||||
"gitlab.com/pztrn/urtrator/configuration"
|
||||
"gitlab.com/pztrn/urtrator/database"
|
||||
"gitlab.com/pztrn/urtrator/eventer"
|
||||
"gitlab.com/pztrn/urtrator/launcher"
|
||||
"gitlab.com/pztrn/urtrator/requester"
|
||||
"gitlab.com/pztrn/urtrator/timer"
|
||||
"gitlab.com/pztrn/urtrator/translator"
|
||||
|
||||
// Github
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
// Github
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
// Caching.
|
||||
Cache *cache.Cache
|
||||
// Clipboard watcher.
|
||||
Clipboard *clipboardwatcher.ClipboardWatcher
|
||||
// Colors parser and prettifier.
|
||||
Colorizer *colorizer.Colorizer
|
||||
// Configuration.
|
||||
Cfg *configuration.Config
|
||||
// Database.
|
||||
Database *database.Database
|
||||
// Eventer.
|
||||
Eventer *eventer.Eventer
|
||||
// Game launcher.
|
||||
Launcher *launcher.Launcher
|
||||
// Requester, which requests server's information.
|
||||
Requester *requester.Requester
|
||||
// Timer.
|
||||
Timer *timer.Timer
|
||||
// Translator.
|
||||
Translator *translator.Translator
|
||||
// Caching.
|
||||
Cache *cache.Cache
|
||||
// Clipboard watcher.
|
||||
Clipboard *clipboardwatcher.ClipboardWatcher
|
||||
// Colors parser and prettifier.
|
||||
Colorizer *colorizer.Colorizer
|
||||
// Configuration.
|
||||
Cfg *configuration.Config
|
||||
// Database.
|
||||
Database *database.Database
|
||||
// Eventer.
|
||||
Eventer *eventer.Eventer
|
||||
// Game launcher.
|
||||
Launcher *launcher.Launcher
|
||||
// Requester, which requests server's information.
|
||||
Requester *requester.Requester
|
||||
// Timer.
|
||||
Timer *timer.Timer
|
||||
// Translator.
|
||||
Translator *translator.Translator
|
||||
}
|
||||
|
||||
func (ctx *Context) Close() error {
|
||||
fmt.Println("Closing URTrator...")
|
||||
fmt.Println("Closing URTrator...")
|
||||
|
||||
launched := ctx.Launcher.CheckForLaunchedUrbanTerror()
|
||||
if launched != nil {
|
||||
return errors.New("Urban Terror is launched!")
|
||||
}
|
||||
ctx.Cache.FlushProfiles(map[string]string{})
|
||||
ctx.Cache.FlushServers(map[string]string{})
|
||||
ctx.Database.Close()
|
||||
launched := ctx.Launcher.CheckForLaunchedUrbanTerror()
|
||||
if launched != nil {
|
||||
return errors.New("Urban Terror is launched!")
|
||||
}
|
||||
ctx.Cache.FlushProfiles(map[string]string{})
|
||||
ctx.Cache.FlushServers(map[string]string{})
|
||||
ctx.Database.Close()
|
||||
|
||||
// At last, close main window.
|
||||
gtk.MainQuit()
|
||||
return nil
|
||||
// At last, close main window.
|
||||
gtk.MainQuit()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeCache() {
|
||||
ctx.Cache = cache.New(ctx.Database, ctx.Eventer)
|
||||
ctx.Cache.Initialize()
|
||||
ctx.Cache = cache.New(ctx.Database, ctx.Eventer)
|
||||
ctx.Cache.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) InitializeClipboardWatcher() {
|
||||
ctx.Clipboard = clipboardwatcher.New(ctx.Cache, ctx.Eventer)
|
||||
ctx.Clipboard.Initialize()
|
||||
ctx.Clipboard = clipboardwatcher.New(ctx.Cache, ctx.Eventer)
|
||||
ctx.Clipboard.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeColorizer() {
|
||||
ctx.Colorizer = colorizer.New()
|
||||
ctx.Colorizer.Initialize()
|
||||
ctx.Colorizer = colorizer.New()
|
||||
ctx.Colorizer.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeConfig() {
|
||||
ctx.Cfg = configuration.New()
|
||||
ctx.Cfg.Initialize()
|
||||
ctx.Cfg = configuration.New()
|
||||
ctx.Cfg.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeDatabase() {
|
||||
ctx.Database = database.New(ctx.Cfg)
|
||||
ctx.Database.Initialize(ctx.Cfg)
|
||||
ctx.Database.Migrate()
|
||||
ctx.Database = database.New(ctx.Cfg)
|
||||
ctx.Database.Initialize(ctx.Cfg)
|
||||
ctx.Database.Migrate()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeEventer() {
|
||||
ctx.Eventer = eventer.New()
|
||||
ctx.Eventer.Initialize()
|
||||
ctx.Eventer = eventer.New()
|
||||
ctx.Eventer.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeLauncher() {
|
||||
ctx.Launcher = launcher.New()
|
||||
ctx.Launcher.Initialize()
|
||||
ctx.Launcher = launcher.New()
|
||||
ctx.Launcher.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeRequester() {
|
||||
ctx.Requester = requester.New(ctx.Cache, ctx.Eventer, ctx.Cfg, ctx.Timer)
|
||||
ctx.Requester.Initialize()
|
||||
ctx.Requester = requester.New(ctx.Cache, ctx.Eventer, ctx.Cfg, ctx.Timer)
|
||||
ctx.Requester.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeTimer() {
|
||||
ctx.Timer = timer.New(ctx.Eventer, ctx.Cfg)
|
||||
ctx.Timer.Initialize()
|
||||
ctx.Timer = timer.New(ctx.Eventer, ctx.Cfg)
|
||||
ctx.Timer.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) initializeTranslator() {
|
||||
ctx.Translator = translator.New(ctx.Cfg)
|
||||
ctx.Translator.Initialize()
|
||||
ctx.Translator = translator.New(ctx.Cfg)
|
||||
ctx.Translator.Initialize()
|
||||
}
|
||||
|
||||
func (ctx *Context) Initialize() {
|
||||
fmt.Println("Initializing application context...")
|
||||
ctx.initializeColorizer()
|
||||
ctx.initializeConfig()
|
||||
ctx.initializeDatabase()
|
||||
ctx.initializeTranslator()
|
||||
ctx.initializeEventer()
|
||||
ctx.initializeCache()
|
||||
ctx.initializeLauncher()
|
||||
ctx.initializeTimer()
|
||||
ctx.initializeRequester()
|
||||
fmt.Println("Initializing application context...")
|
||||
ctx.initializeColorizer()
|
||||
ctx.initializeConfig()
|
||||
ctx.initializeDatabase()
|
||||
ctx.initializeTranslator()
|
||||
ctx.initializeEventer()
|
||||
ctx.initializeCache()
|
||||
ctx.initializeLauncher()
|
||||
ctx.initializeTimer()
|
||||
ctx.initializeRequester()
|
||||
}
|
||||
|
@ -10,85 +10,84 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
//"database/sql"
|
||||
"fmt"
|
||||
"path"
|
||||
"runtime"
|
||||
"strconv"
|
||||
// stdlib
|
||||
//"database/sql"
|
||||
"fmt"
|
||||
"path"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/configuration"
|
||||
"github.com/pztrn/urtrator/datamodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/configuration"
|
||||
"gitlab.com/pztrn/urtrator/datamodels"
|
||||
|
||||
// Other
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
// Other
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
// Configuration.
|
||||
cfg *configuration.Config
|
||||
// Pointer to initialized database connection.
|
||||
Db *sqlx.DB
|
||||
// Configuration.
|
||||
cfg *configuration.Config
|
||||
// Pointer to initialized database connection.
|
||||
Db *sqlx.DB
|
||||
}
|
||||
|
||||
func (d *Database) Close() {
|
||||
fmt.Println("Closing database...")
|
||||
fmt.Println("Closing database...")
|
||||
|
||||
// Save configuration.
|
||||
// Delete previous configuration.
|
||||
d.Db.MustExec("DELETE FROM configuration")
|
||||
tx := d.Db.MustBegin()
|
||||
for k, v := range cfg.Cfg {
|
||||
cfg_item := datamodels.Configuration{}
|
||||
cfg_item.Key = k
|
||||
cfg_item.Value = v
|
||||
tx.NamedExec("INSERT INTO configuration (key, value) VALUES (:key, :value)", &cfg_item)
|
||||
}
|
||||
tx.Commit()
|
||||
// Save configuration.
|
||||
// Delete previous configuration.
|
||||
d.Db.MustExec("DELETE FROM configuration")
|
||||
tx := d.Db.MustBegin()
|
||||
for k, v := range cfg.Cfg {
|
||||
cfg_item := datamodels.Configuration{}
|
||||
cfg_item.Key = k
|
||||
cfg_item.Value = v
|
||||
tx.NamedExec("INSERT INTO configuration (key, value) VALUES (:key, :value)", &cfg_item)
|
||||
}
|
||||
tx.Commit()
|
||||
|
||||
d.Db.Close()
|
||||
d.Db.Close()
|
||||
|
||||
runtime.UnlockOSThread()
|
||||
runtime.UnlockOSThread()
|
||||
}
|
||||
|
||||
func (d *Database) Initialize(cfg *configuration.Config) {
|
||||
fmt.Println("Initializing database...")
|
||||
fmt.Println("Initializing database...")
|
||||
|
||||
runtime.LockOSThread()
|
||||
runtime.LockOSThread()
|
||||
|
||||
// Connect to database.
|
||||
db_path := path.Join(cfg.TEMP["DATA"], "database.sqlite3")
|
||||
fmt.Println("Database path: " + db_path)
|
||||
db, err := sqlx.Connect("sqlite3", db_path)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
d.Db = db
|
||||
// Connect to database.
|
||||
db_path := path.Join(cfg.TEMP["DATA"], "database.sqlite3")
|
||||
fmt.Println("Database path: " + db_path)
|
||||
db, err := sqlx.Connect("sqlite3", db_path)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
d.Db = db
|
||||
|
||||
// Load configuration.
|
||||
cfgs := []datamodels.Configuration{}
|
||||
d.Db.Select(&cfgs, "SELECT * FROM configuration")
|
||||
if len(cfgs) > 0 {
|
||||
for i := range cfgs {
|
||||
cfg.Cfg[cfgs[i].Key] = cfgs[i].Value
|
||||
}
|
||||
}
|
||||
// Load configuration.
|
||||
cfgs := []datamodels.Configuration{}
|
||||
d.Db.Select(&cfgs, "SELECT * FROM configuration")
|
||||
if len(cfgs) > 0 {
|
||||
for i := range cfgs {
|
||||
cfg.Cfg[cfgs[i].Key] = cfgs[i].Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Database) Migrate() {
|
||||
// Getting current database version.
|
||||
dbver := 0
|
||||
database := []datamodels.Database{}
|
||||
d.Db.Select(&database, "SELECT * FROM database")
|
||||
if len(database) > 0 {
|
||||
fmt.Println("Current database version: " + database[0].Version)
|
||||
dbver, _ = strconv.Atoi(database[0].Version)
|
||||
} else {
|
||||
fmt.Println("No database found, will create new one")
|
||||
}
|
||||
// Getting current database version.
|
||||
dbver := 0
|
||||
database := []datamodels.Database{}
|
||||
d.Db.Select(&database, "SELECT * FROM database")
|
||||
if len(database) > 0 {
|
||||
fmt.Println("Current database version: " + database[0].Version)
|
||||
dbver, _ = strconv.Atoi(database[0].Version)
|
||||
} else {
|
||||
fmt.Println("No database found, will create new one")
|
||||
}
|
||||
|
||||
|
||||
migrate_full(d, dbver)
|
||||
migrate_full(d, dbver)
|
||||
}
|
||||
|
@ -10,16 +10,16 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
// Local
|
||||
"github.com/pztrn/urtrator/configuration"
|
||||
// Local
|
||||
"gitlab.com/pztrn/urtrator/configuration"
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *configuration.Config
|
||||
cfg *configuration.Config
|
||||
)
|
||||
|
||||
func New(c *configuration.Config) *Database {
|
||||
cfg = c
|
||||
d := Database{}
|
||||
return &d
|
||||
cfg = c
|
||||
d := Database{}
|
||||
return &d
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ fi
|
||||
|
||||
# Okay, let's compile.
|
||||
echo "Getting URTrator (and dependencies) sources"
|
||||
go get -u -v -d github.com/pztrn/urtrator
|
||||
go get -u -v -d gitlab.com/pztrn/urtrator
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to get URTrator sources"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building URTrator..."
|
||||
go install -v github.com/pztrn/urtrator
|
||||
go install -v gitlab.com/pztrn/urtrator
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to build URTrator! Please, create a new bug report at https://github.com/pztrn/urtrator and attach FULL console output!"
|
||||
exit 1
|
||||
@ -69,7 +69,7 @@ mkdir -p URTrator.app/Contents/{MacOS,Framework,Resources}
|
||||
# Copying URTrator binary
|
||||
cp $GOPATH/bin/urtrator URTrator.app/Contents/MacOS/
|
||||
# Copying main resources.
|
||||
cp $GOPATH/src/github.com/pztrn/urtrator/artwork/urtrator.icns ./URTrator.app/Contents/Resources/
|
||||
cp $GOPATH/src/gitlab.com/pztrn/urtrator/artwork/urtrator.icns ./URTrator.app/Contents/Resources/
|
||||
cp -R ./Resources/themes ./URTrator.app/Contents/Resources/
|
||||
|
||||
#####################################################################
|
||||
@ -90,7 +90,7 @@ INFOPLIST='<?xml version="1.0" encoding="UTF-8"?>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>urtrator.icns</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.1.0</string>
|
||||
<string>0.2.0</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
|
@ -10,128 +10,128 @@
|
||||
package launcher
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
// stdlib
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/datamodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/datamodels"
|
||||
|
||||
// Github
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
// Github
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
type Launcher struct {
|
||||
// Flags.
|
||||
// Is Urban Terror launched ATM?
|
||||
launched bool
|
||||
// Flags.
|
||||
// Is Urban Terror launched ATM?
|
||||
launched bool
|
||||
}
|
||||
|
||||
func (l *Launcher) CheckForLaunchedUrbanTerror() error {
|
||||
if l.launched {
|
||||
// Temporary disable all these modals on Linux.
|
||||
// See https://github.com/mattn/go-gtk/issues/289.
|
||||
if runtime.GOOS != "linux" {
|
||||
mbox_string := "Game is launched.\n\nCannot quit, because game is launched.\nQuit Urban Terror to exit URTrator!"
|
||||
m := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, mbox_string)
|
||||
m.Response(func() {
|
||||
m.Destroy()
|
||||
})
|
||||
m.Run()
|
||||
return errors.New("User didn't select valid profile, mismatch with server's version.")
|
||||
}
|
||||
}
|
||||
if l.launched {
|
||||
// Temporary disable all these modals on Linux.
|
||||
// See https://github.com/mattn/go-gtk/issues/289.
|
||||
if runtime.GOOS != "linux" {
|
||||
mbox_string := "Game is launched.\n\nCannot quit, because game is launched.\nQuit Urban Terror to exit URTrator!"
|
||||
m := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, mbox_string)
|
||||
m.Response(func() {
|
||||
m.Destroy()
|
||||
})
|
||||
m.Run()
|
||||
return errors.New("User didn't select valid profile, mismatch with server's version.")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Launcher) findFreeDisplay() string {
|
||||
current_display_raw := os.Getenv("DISPLAY")
|
||||
current_display, _ := strconv.Atoi(strings.Split(current_display_raw, ":")[1])
|
||||
current_display += 1
|
||||
return strconv.Itoa(current_display)
|
||||
current_display_raw := os.Getenv("DISPLAY")
|
||||
current_display, _ := strconv.Atoi(strings.Split(current_display_raw, ":")[1])
|
||||
current_display += 1
|
||||
return strconv.Itoa(current_display)
|
||||
}
|
||||
|
||||
func (l *Launcher) Initialize() {
|
||||
fmt.Println("Initializing game launcher...")
|
||||
fmt.Println("Initializing game launcher...")
|
||||
}
|
||||
|
||||
func (l *Launcher) Launch(server_profile *datamodels.Server, user_profile *datamodels.Profile, password string, additional_parameters []string, callback func()) {
|
||||
// ToDo: only one instance of Urban Terror should be launched, so button
|
||||
// should be disabled.
|
||||
fmt.Println("Launching Urban Terror...")
|
||||
// ToDo: only one instance of Urban Terror should be launched, so button
|
||||
// should be disabled.
|
||||
fmt.Println("Launching Urban Terror...")
|
||||
|
||||
done := make(chan bool, 1)
|
||||
done := make(chan bool, 1)
|
||||
|
||||
// Create launch string.
|
||||
var launch_bin string = ""
|
||||
launch_bin, err := exec.LookPath(user_profile.Binary)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
// Create launch string.
|
||||
var launch_bin string = ""
|
||||
launch_bin, err := exec.LookPath(user_profile.Binary)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
server_address := server_profile.Ip + ":" + server_profile.Port
|
||||
server_address := server_profile.Ip + ":" + server_profile.Port
|
||||
|
||||
var launch_params []string
|
||||
if len(server_address) > 0 {
|
||||
launch_params = append(launch_params, "+connect", server_address)
|
||||
}
|
||||
if len(password) > 0 {
|
||||
launch_params = append(launch_params, "+password", password)
|
||||
}
|
||||
if len(user_profile.Additional_params) > 0 {
|
||||
additional_params := strings.Split(user_profile.Additional_params, " ")
|
||||
launch_params = append(launch_params, additional_params...)
|
||||
}
|
||||
if len(additional_parameters) > 0 {
|
||||
for i := range additional_parameters {
|
||||
launch_params = append(launch_params, additional_parameters[i])
|
||||
}
|
||||
}
|
||||
if runtime.GOOS == "linux" && user_profile.Second_x_session == "1" {
|
||||
launch_params = append([]string{launch_bin}, launch_params...)
|
||||
display := l.findFreeDisplay()
|
||||
launch_bin, err = exec.LookPath("xinit")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
launch_params = append(launch_params, "--", ":" + display)
|
||||
}
|
||||
if runtime.GOOS == "darwin" {
|
||||
// On macOS we should not start binary, but application bundle.
|
||||
// So we will obtain app bundle path.
|
||||
bundle_path := strings.Split(launch_bin, "/Contents")[0]
|
||||
// and create special launch string, which involves open.
|
||||
launch_bin = "/usr/bin/open"
|
||||
launch_params = append([]string{launch_bin, "-W", "-a", bundle_path, "--args"}, launch_params...)
|
||||
}
|
||||
fmt.Println(launch_bin, launch_params)
|
||||
go func() {
|
||||
go func() {
|
||||
cmd := exec.Command(launch_bin, launch_params...)
|
||||
// This workaround is required on Windows, otherwise ioq3
|
||||
// will not find game data.
|
||||
if runtime.GOOS == "windows" {
|
||||
dir := filepath.Dir(launch_bin)
|
||||
cmd.Dir = dir
|
||||
}
|
||||
out, err1 := cmd.Output()
|
||||
if err1 != nil {
|
||||
fmt.Println("Launch error: " + err1.Error())
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
done <- true
|
||||
}()
|
||||
var launch_params []string
|
||||
if len(server_address) > 0 {
|
||||
launch_params = append(launch_params, "+connect", server_address)
|
||||
}
|
||||
if len(password) > 0 {
|
||||
launch_params = append(launch_params, "+password", password)
|
||||
}
|
||||
if len(user_profile.Additional_params) > 0 {
|
||||
additional_params := strings.Split(user_profile.Additional_params, " ")
|
||||
launch_params = append(launch_params, additional_params...)
|
||||
}
|
||||
if len(additional_parameters) > 0 {
|
||||
for i := range additional_parameters {
|
||||
launch_params = append(launch_params, additional_parameters[i])
|
||||
}
|
||||
}
|
||||
if runtime.GOOS == "linux" && user_profile.Second_x_session == "1" {
|
||||
launch_params = append([]string{launch_bin}, launch_params...)
|
||||
display := l.findFreeDisplay()
|
||||
launch_bin, err = exec.LookPath("xinit")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
launch_params = append(launch_params, "--", ":"+display)
|
||||
}
|
||||
if runtime.GOOS == "darwin" {
|
||||
// On macOS we should not start binary, but application bundle.
|
||||
// So we will obtain app bundle path.
|
||||
bundle_path := strings.Split(launch_bin, "/Contents")[0]
|
||||
// and create special launch string, which involves open.
|
||||
launch_bin = "/usr/bin/open"
|
||||
launch_params = append([]string{launch_bin, "-W", "-a", bundle_path, "--args"}, launch_params...)
|
||||
}
|
||||
fmt.Println(launch_bin, launch_params)
|
||||
go func() {
|
||||
go func() {
|
||||
cmd := exec.Command(launch_bin, launch_params...)
|
||||
// This workaround is required on Windows, otherwise ioq3
|
||||
// will not find game data.
|
||||
if runtime.GOOS == "windows" {
|
||||
dir := filepath.Dir(launch_bin)
|
||||
cmd.Dir = dir
|
||||
}
|
||||
out, err1 := cmd.Output()
|
||||
if err1 != nil {
|
||||
fmt.Println("Launch error: " + err1.Error())
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
done <- true
|
||||
}()
|
||||
|
||||
select {
|
||||
case <- done:
|
||||
callback()
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case <-done:
|
||||
callback()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -10,29 +10,29 @@
|
||||
package requester
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"fmt"
|
||||
// stdlib
|
||||
"fmt"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/cache"
|
||||
"github.com/pztrn/urtrator/configuration"
|
||||
"github.com/pztrn/urtrator/eventer"
|
||||
"github.com/pztrn/urtrator/timer"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/cache"
|
||||
"gitlab.com/pztrn/urtrator/configuration"
|
||||
"gitlab.com/pztrn/urtrator/eventer"
|
||||
"gitlab.com/pztrn/urtrator/timer"
|
||||
)
|
||||
|
||||
var (
|
||||
Cache *cache.Cache
|
||||
Cfg *configuration.Config
|
||||
Eventer *eventer.Eventer
|
||||
Timer *timer.Timer
|
||||
Cache *cache.Cache
|
||||
Cfg *configuration.Config
|
||||
Eventer *eventer.Eventer
|
||||
Timer *timer.Timer
|
||||
)
|
||||
|
||||
func New(c *cache.Cache, e *eventer.Eventer, cc *configuration.Config, t *timer.Timer) *Requester {
|
||||
Cache = c
|
||||
Cfg = cc
|
||||
Eventer = e
|
||||
Timer = t
|
||||
fmt.Println("Creating Requester object...")
|
||||
r := Requester{}
|
||||
return &r
|
||||
Cache = c
|
||||
Cfg = cc
|
||||
Eventer = e
|
||||
Timer = t
|
||||
fmt.Println("Creating Requester object...")
|
||||
r := Requester{}
|
||||
return &r
|
||||
}
|
||||
|
@ -10,281 +10,281 @@
|
||||
package requester
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
// stdlib
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
// local
|
||||
"github.com/pztrn/urtrator/datamodels"
|
||||
// local
|
||||
"gitlab.com/pztrn/urtrator/datamodels"
|
||||
)
|
||||
|
||||
type Pooler struct {
|
||||
// Maximum number of simultaneous requests running.
|
||||
maxrequests int
|
||||
// Packet prefix.
|
||||
pp string
|
||||
// Current requests counter mutex.
|
||||
cur_requests_mutex sync.Mutex
|
||||
// Maximum number of simultaneous requests running.
|
||||
maxrequests int
|
||||
// Packet prefix.
|
||||
pp string
|
||||
// Current requests counter mutex.
|
||||
cur_requests_mutex sync.Mutex
|
||||
}
|
||||
|
||||
func (p *Pooler) Initialize() {
|
||||
fmt.Println("Initializing requester goroutine pooler...")
|
||||
// ToDo: figure out how to make this work nice.
|
||||
p.maxrequests = 150
|
||||
_ = runtime.GOMAXPROCS(runtime.NumCPU() * 4)
|
||||
p.pp = "\377\377\377\377"
|
||||
fmt.Println("Pooler initialized")
|
||||
fmt.Println("Initializing requester goroutine pooler...")
|
||||
// ToDo: figure out how to make this work nice.
|
||||
p.maxrequests = 150
|
||||
_ = runtime |