-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
661164c
commit 56c7e10
Showing
18 changed files
with
1,338 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Details] | ||
Icon = "assets/wallet-icon.png" | ||
Name = "balance" | ||
ID = "slotopol.balance" | ||
Version = "0.0.0" | ||
Build = 12 | ||
|
||
[Development] | ||
HelperText = "This binary was built with debug symbols" | ||
|
||
[Release] | ||
HelperText = "This binary was built without debug symbols" | ||
|
||
[LinuxAndBSD] | ||
GenericName = "Slotopol Balance" | ||
Categories = ["Games"] | ||
Comment = "Helps to add money to users wallets on Slotopol Server." | ||
Keywords = ["slot", "casino", "gambling"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# balance | ||
# Balance | ||
|
||
[![Hits-of-Code](https://hitsofcode.com/github/slotopol/balance?branch=main)](https://hitsofcode.com/github/slotopol/balance/view?branch=main) | ||
|
||
GUI tool application that helps to change users balance for Slotopol server. | ||
|
||
First release of application is not ready yet. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
hostaddr: http://localhost:8080 | ||
email: [email protected] | ||
secret: 0YBoaT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
- [email protected] | ||
- [email protected] | ||
- [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package cfg | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/viper" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const ( | ||
cfgcredentials = "balance-credentials.yaml" | ||
cfguserlist = "balance-userlist.yaml" | ||
) | ||
|
||
var ( | ||
// Executable path. | ||
ExePath string | ||
// Configuration file with path. | ||
CfgFile string | ||
// Configuration path. | ||
CfgPath string | ||
) | ||
|
||
func init() { | ||
var err error | ||
|
||
// Executable path | ||
ExePath = func() string { | ||
if str, err := os.Executable(); err == nil { | ||
return filepath.Dir(str) | ||
} else { | ||
return filepath.Dir(os.Args[0]) | ||
} | ||
}() | ||
|
||
// Config path | ||
const sub = "config" | ||
// Search config in home directory with name "balance" (without extension). | ||
viper.SetConfigName("balance-app") | ||
viper.SetConfigType("yaml") | ||
if env, ok := os.LookupEnv("CFGFILE"); ok { | ||
viper.AddConfigPath(env) | ||
} | ||
viper.AddConfigPath(filepath.Join(ExePath, sub)) | ||
viper.AddConfigPath(ExePath) | ||
viper.AddConfigPath(sub) | ||
viper.AddConfigPath(".") | ||
if home, err := os.UserHomeDir(); err == nil { | ||
viper.AddConfigPath(filepath.Join(home, sub)) | ||
viper.AddConfigPath(home) | ||
} | ||
if env, ok := os.LookupEnv("GOBIN"); ok { | ||
viper.AddConfigPath(filepath.Join(env, sub)) | ||
viper.AddConfigPath(env) | ||
} else if env, ok := os.LookupEnv("GOPATH"); ok { | ||
viper.AddConfigPath(filepath.Join(env, "bin", sub)) | ||
viper.AddConfigPath(filepath.Join(env, "bin")) | ||
} | ||
|
||
viper.AutomaticEnv() | ||
|
||
if err = viper.ReadInConfig(); err != nil { | ||
log.Println("config file not found!") | ||
} else { | ||
viper.Unmarshal(&Cfg) | ||
CfgFile = viper.ConfigFileUsed() | ||
CfgPath = filepath.Dir(CfgFile) | ||
log.Printf("config path: %s\n", CfgPath) | ||
} | ||
} | ||
|
||
func ReadCredentials() (err error) { | ||
var b []byte | ||
if b, err = os.ReadFile(filepath.Join(CfgPath, cfgcredentials)); err != nil { | ||
return | ||
} | ||
if yaml.Unmarshal(b, Credentials); err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
func ReadUserList() (err error) { | ||
var b []byte | ||
if b, err = os.ReadFile(filepath.Join(CfgPath, cfguserlist)); err != nil { | ||
return | ||
} | ||
if yaml.Unmarshal(b, &UserList); err != nil { | ||
return | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cfg | ||
|
||
import "time" | ||
|
||
var ( | ||
// Admin credentials. | ||
Credentials = &struct { | ||
Addr string `json:"hostaddr" yaml:"hostaddr" mapstructure:"hostaddr"` | ||
Email string `json:"email" yaml:"email" mapstructure:"email"` | ||
Secret string `json:"secret" yaml:"secret" mapstructure:"secret"` | ||
}{ | ||
Addr: "http://localhost:8080", | ||
Email: "[email protected]", | ||
Secret: "0YBoaT", | ||
} | ||
|
||
// List of registered users emails. | ||
UserList = []string{ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
} | ||
|
||
// Config is common application settings. | ||
Cfg = &struct { | ||
PropUpdateTick time.Duration `json:"prop-update-tick" yaml:"prop-update-tick" mapstructure:"prop-update-tick"` | ||
}{ | ||
PropUpdateTick: time.Millisecond * 4000, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package core | ||
|
||
import ( | ||
"encoding/xml" | ||
"time" | ||
) | ||
|
||
var admin AuthResp | ||
|
||
type ( | ||
ArgSignIs struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"arg"` | ||
UID uint64 `json:"uid" yaml:"uid" xml:"uid"` | ||
Email string `json:"email" yaml:"email" xml:"email"` | ||
} | ||
RetSignIs struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"` | ||
UID uint64 `json:"uid" yaml:"uid" xml:"uid"` | ||
Email string `json:"email" yaml:"email" xml:"email"` | ||
Name string `json:"name,omitempty" yaml:"name,omitempty" xml:"name,omitempty"` | ||
} | ||
AuthResp struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"` | ||
UID uint64 `json:"uid" yaml:"uid" xml:"uid"` | ||
Email string `json:"email" yaml:"email" xml:"email"` | ||
Access string `json:"access" yaml:"access" xml:"access"` | ||
Refrsh string `json:"refrsh" yaml:"refrsh" xml:"refrsh"` | ||
Expire string `json:"expire" yaml:"expire" xml:"expire"` | ||
Living string `json:"living" yaml:"living" xml:"living"` | ||
} | ||
ArgSignIn struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"arg"` | ||
UID uint64 `json:"uid" yaml:"uid" xml:"uid"` | ||
Email string `json:"email" yaml:"email" xml:"email"` | ||
Secret string `json:"secret" yaml:"secret,omitempty" xml:"secret,omitempty"` | ||
HS256 string `json:"hs256,omitempty" yaml:"hs256,omitempty" xml:"hs256,omitempty"` | ||
SigTime string `json:"sigtime,omitempty" yaml:"sigtime,omitempty" xml:"sigtime,omitempty"` | ||
Code uint32 `json:"code,omitempty" yaml:"code,omitempty" xml:"code,omitempty"` | ||
} | ||
) | ||
|
||
func ApiSignIs(email string) (user User, err error) { | ||
var arg = ArgSignIs{ | ||
Email: email, | ||
} | ||
var ret RetSignIs | ||
ret, _, err = HttpPost[ArgSignIs, RetSignIs]("/user/is", admin.Access, &arg) | ||
user.UID = ret.UID | ||
user.Email = ret.Email | ||
user.Name = ret.Name | ||
return | ||
} | ||
|
||
func ApiSignIn(email, secret string) (ret AuthResp, err error) { | ||
var arg ArgSignIn | ||
arg.Email = email | ||
arg.Secret = secret | ||
ret, _, err = HttpPost[ArgSignIn, AuthResp]("/signin", "", &arg) | ||
return | ||
} | ||
|
||
func ApiRefresh() (ret AuthResp, err error) { | ||
ret, _, err = HttpPost[any, AuthResp]("/refresh", admin.Access, nil) | ||
return | ||
} | ||
|
||
type ( | ||
clubitem struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"club"` | ||
CID uint64 `json:"cid" yaml:"cid" xml:"cid,attr"` | ||
Name string `json:"name,omitempty" yaml:"name,omitempty" xml:"name,omitempty"` | ||
} | ||
RetClubList struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"` | ||
List []clubitem `json:"list" yaml:"list" xml:"list>club" form:"list"` | ||
} | ||
) | ||
|
||
func ApiClubList() (ret RetClubList, err error) { | ||
ret, _, err = HttpPost[any, RetClubList]("/club/list", admin.Access, nil) | ||
return | ||
} | ||
|
||
type ( | ||
ArgPropGet struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"arg"` | ||
CID uint64 `json:"cid" yaml:"cid" xml:"cid,attr"` | ||
UID uint64 `json:"uid" yaml:"uid" xml:"uid,attr"` | ||
} | ||
RetPropGet struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"` | ||
Wallet float64 `json:"wallet" yaml:"wallet" xml:"wallet"` | ||
Access AL `json:"access" yaml:"access" xml:"access"` | ||
MRTP float64 `json:"mrtp" yaml:"mrtp" xml:"mrtp"` | ||
} | ||
RetWalletGet struct { | ||
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"` | ||
Wallet float64 `json:"wallet" yaml:"wallet" xml:"wallet"` | ||
} | ||
) | ||
|
||
func ApiPropGet(cid, uid uint64) (p Props, err error) { | ||
var arg = ArgPropGet{ | ||
CID: cid, | ||
UID: uid, | ||
} | ||
var ret RetPropGet | ||
ret, _, err = HttpPost[ArgPropGet, RetPropGet]("/prop/get", admin.Access, &arg) | ||
p = Props{ | ||
Wallet: ret.Wallet, | ||
Access: ret.Access, | ||
MRTP: ret.MRTP, | ||
last: time.Now(), | ||
} | ||
return | ||
} | ||
|
||
func ApiWalletGet(cid, uid uint64) (sum float64, err error) { | ||
var arg = ArgPropGet{ | ||
CID: cid, | ||
UID: uid, | ||
} | ||
var ret RetWalletGet | ||
ret, _, err = HttpPost[ArgPropGet, RetWalletGet]("/prop/wallet/get", admin.Access, &arg) | ||
sum = ret.Wallet | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package core | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
|
||
cfg "github.com/slotopol/balance/config" | ||
) | ||
|
||
type ajaxerr struct { | ||
What string `json:"what" yaml:"what" xml:"what"` | ||
Code int `json:"code,omitempty" yaml:"code,omitempty" xml:"code,omitempty"` | ||
UID uint64 `json:"uid,omitempty" yaml:"uid,omitempty" xml:"uid,omitempty,attr"` | ||
} | ||
|
||
func (err ajaxerr) Error() string { | ||
return fmt.Sprintf("what: %s, code: %d", err.What, err.Code) | ||
} | ||
|
||
func HttpPost[Ta, Tr any](path string, token string, arg *Ta) (ret Tr, status int, err error) { | ||
defer func() { | ||
if err != nil { | ||
log.Printf("error on api call '%s': %s", path, err.Error()) | ||
} | ||
}() | ||
var b []byte | ||
if arg != nil { | ||
if b, err = json.Marshal(arg); err != nil { | ||
return | ||
} | ||
} | ||
var req *http.Request | ||
if req, err = http.NewRequest("POST", cfg.Credentials.Addr+path, bytes.NewReader(b)); err != nil { | ||
return | ||
} | ||
req.Header.Add("Content-Type", "application/json") | ||
req.Header.Add("Accept", "application/json") | ||
if token != "" { | ||
req.Header.Add("Authorization", "Bearer "+token) | ||
} | ||
|
||
var resp *http.Response | ||
if resp, err = http.DefaultClient.Do(req); err != nil { | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
status = resp.StatusCode | ||
if b, err = io.ReadAll(resp.Body); err != nil { | ||
return | ||
} | ||
if resp.StatusCode >= http.StatusBadRequest { | ||
var aerr ajaxerr | ||
if err = json.Unmarshal(b, &aerr); err != nil { | ||
return | ||
} | ||
err = &aerr | ||
return | ||
} | ||
if resp.StatusCode != http.StatusOK { | ||
return | ||
} | ||
if err = json.Unmarshal(b, &ret); err != nil { | ||
return | ||
} | ||
return | ||
} |
Oops, something went wrong.