-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
29 changed files
with
505 additions
and
133 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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
# Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
# custom | ||
.vscode | ||
|
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
package database | ||
|
||
func ConnectAll() { | ||
connectMongo() | ||
connectPostgres() | ||
} |
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,41 +1,27 @@ | ||
package main | ||
package database | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"time" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/globals" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
var mongoClient *mongo.Client | ||
var mongoContext context.Context | ||
var mongoDatabase *mongo.Database | ||
var mongoCollection *mongo.Collection | ||
var MongoCollection *mongo.Collection | ||
|
||
func connectMongo() { | ||
mongoClient, _ = mongo.NewClient(options.Client().ApplyURI(os.Getenv("MONGO_URI"))) | ||
mongoContext, _ = context.WithTimeout(context.Background(), 10*time.Second) | ||
_ = mongoClient.Connect(mongoContext) | ||
|
||
mongoDatabase = mongoClient.Database("pretendo") | ||
mongoCollection = mongoDatabase.Collection("nexaccounts") | ||
} | ||
|
||
func getNEXAccountByPID(pid uint32) bson.M { | ||
var result bson.M | ||
|
||
err := mongoCollection.FindOne(context.TODO(), bson.D{{Key: "pid", Value: pid}}, options.FindOne()).Decode(&result) | ||
|
||
if err != nil { | ||
if err == mongo.ErrNoDocuments { | ||
return nil | ||
} | ||
|
||
panic(err) | ||
} | ||
MongoCollection = mongoDatabase.Collection("pnids") | ||
|
||
return result | ||
globals.Logger.Success("Connected to Mongo!") | ||
} |
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,25 @@ | ||
package database | ||
|
||
import ( | ||
"database/sql" | ||
"os" | ||
|
||
_ "github.com/lib/pq" | ||
|
||
"github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/globals" | ||
) | ||
|
||
var Postgres *sql.DB | ||
|
||
func connectPostgres() { | ||
var err error | ||
|
||
Postgres, err = sql.Open("postgres", os.Getenv("DATABASE_URI")) | ||
if err != nil { | ||
globals.Logger.Critical(err.Error()) | ||
} | ||
|
||
globals.Logger.Success("Connected to Postgres!") | ||
|
||
initPostgres() | ||
} |
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,12 @@ | ||
package database | ||
|
||
import ( | ||
"github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/globals" | ||
) | ||
|
||
func DeleteMetaBinaryByDataID(dataID uint32) { | ||
_, err := Postgres.Exec(`DELETE FROM mvdkts.meta_binaries WHERE data_id=$1`, dataID) | ||
if err != nil { | ||
globals.Logger.Critical(err.Error()) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
database/get_meta_binary_by_type_and_owner_pid_and_slot_id.go
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,47 @@ | ||
package database | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/globals" | ||
"github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/types" | ||
"github.com/lib/pq" | ||
) | ||
|
||
func GetMetaBinaryByTypeAndOwnerPIDAndSlotID(dataType uint16, pid uint32, slotID uint8) *types.MetaBinary { | ||
metaBinary := types.NewMetaBinary() | ||
|
||
err := Postgres.QueryRow(` | ||
SELECT | ||
data_id, | ||
owner_pid, | ||
name, | ||
data_type, | ||
meta_binary, | ||
permission, | ||
del_permission, | ||
flag, | ||
period, | ||
tags, | ||
persistence_slot_id, | ||
extra_data | ||
FROM mvdkts.meta_binaries WHERE data_type=$1 AND owner_pid=$2 AND persistence_slot_id=$3`, dataType, pid, slotID).Scan( | ||
&metaBinary.DataID, | ||
&metaBinary.OwnerPID, | ||
&metaBinary.Name, | ||
&metaBinary.DataType, | ||
&metaBinary.Buffer, | ||
&metaBinary.Permission, | ||
&metaBinary.DeletePermission, | ||
&metaBinary.Flag, | ||
&metaBinary.Period, | ||
pq.Array(&metaBinary.Tags), | ||
&metaBinary.PersistenceSlotID, | ||
pq.Array(&metaBinary.ExtraData), | ||
) | ||
if err != nil && err != sql.ErrNoRows { | ||
globals.Logger.Critical(err.Error()) | ||
} | ||
|
||
return metaBinary | ||
} |
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,37 @@ | ||
package database | ||
|
||
import "github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/globals" | ||
|
||
func initPostgres() { | ||
var err error | ||
|
||
_, err = Postgres.Exec(`CREATE SCHEMA IF NOT EXISTS mvdkts`) | ||
if err != nil { | ||
globals.Logger.Critical(err.Error()) | ||
return | ||
} | ||
|
||
globals.Logger.Success("Postgres schema created") | ||
|
||
// TODO - Store ratings for meta binaries | ||
_, err = Postgres.Exec(`CREATE TABLE IF NOT EXISTS mvdkts.meta_binaries ( | ||
data_id serial PRIMARY KEY, | ||
owner_pid integer, | ||
name text, | ||
data_type smallint, | ||
meta_binary bytea, | ||
permission smallint, | ||
del_permission smallint, | ||
flag smallint, | ||
period smallint, | ||
tags text[], | ||
persistence_slot_id smallint, | ||
extra_data text[] | ||
)`) | ||
if err != nil { | ||
globals.Logger.Critical(err.Error()) | ||
return | ||
} | ||
|
||
globals.Logger.Success("Postgres tables created") | ||
} |
44 changes: 44 additions & 0 deletions
44
database/insert_meta_binary_by_datastore_prepare_post_param_with_owner_pid.go
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,44 @@ | ||
package database | ||
|
||
import ( | ||
"github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/globals" | ||
nexproto "github.com/PretendoNetwork/nex-protocols-go" | ||
"github.com/lib/pq" | ||
) | ||
|
||
func InsertMetaBinaryByDataStorePreparePostParamWithOwnerPID(dataStorePreparePostParam *nexproto.DataStorePreparePostParam, pid uint32) uint32 { | ||
var dataID uint32 | ||
|
||
err := Postgres.QueryRow(` | ||
INSERT INTO mvdkts.meta_binaries ( | ||
owner_pid, | ||
name, | ||
data_type, | ||
meta_binary, | ||
permission, | ||
del_permission, | ||
flag, | ||
period, | ||
tags, | ||
persistence_slot_id, | ||
extra_data | ||
) | ||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING data_id`, | ||
pid, | ||
dataStorePreparePostParam.Name, | ||
dataStorePreparePostParam.DataType, | ||
dataStorePreparePostParam.MetaBinary, | ||
dataStorePreparePostParam.Permission.Permission, | ||
dataStorePreparePostParam.DelPermission.Permission, | ||
dataStorePreparePostParam.Flag, | ||
dataStorePreparePostParam.Period, | ||
pq.Array(dataStorePreparePostParam.Tags), | ||
dataStorePreparePostParam.PersistenceInitParam.PersistenceSlotId, | ||
pq.Array(dataStorePreparePostParam.ExtraData), | ||
).Scan(&dataID) | ||
if err != nil { | ||
globals.Logger.Critical(err.Error()) | ||
} | ||
|
||
return dataID | ||
} |
38 changes: 38 additions & 0 deletions
38
database/update_meta_binary_by_datastore_change_meta_param.go
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,38 @@ | ||
package database | ||
|
||
import ( | ||
nexproto "github.com/PretendoNetwork/nex-protocols-go" | ||
"github.com/lib/pq" | ||
) | ||
|
||
func UpdateMetaBinaryByDataStoreChangeMetaParam(dataStoreChangeMetaParam *nexproto.DataStoreChangeMetaParam) error { | ||
// TODO - Check dataStoreChangeMetaParam.ModifiesFlag | ||
// TODO - Check dataStoreChangeMetaParam.CompareParam | ||
|
||
_, err := Postgres.Exec(` | ||
UPDATE mvdkts.meta_binaries | ||
SET | ||
name=$1, | ||
permission=$2, | ||
del_permission=$3, | ||
period=$4, | ||
meta_binary=$5, | ||
tags=$6, | ||
data_type=$7 | ||
WHERE data_id=$8`, | ||
dataStoreChangeMetaParam.Name, | ||
dataStoreChangeMetaParam.Permission.Permission, | ||
dataStoreChangeMetaParam.DelPermission.Permission, | ||
dataStoreChangeMetaParam.Period, | ||
dataStoreChangeMetaParam.MetaBinary, | ||
pq.Array(dataStoreChangeMetaParam.Tags), | ||
dataStoreChangeMetaParam.DataType, | ||
dataStoreChangeMetaParam.DataID, | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
package globals | ||
|
||
import ( | ||
"github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/plogger-go" | ||
) | ||
|
||
var Logger = plogger.NewLogger() | ||
var NEXServer *nex.Server |
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
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,43 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sync" | ||
|
||
"github.com/PretendoNetwork/nex-go" | ||
secureconnection "github.com/PretendoNetwork/nex-protocols-common-go/secure-connection" | ||
"github.com/PretendoNetwork/mario-vs-dk-tipping-stars-secure/nex" | ||
) | ||
|
||
var nexServer *nex.Server | ||
var wg sync.WaitGroup | ||
|
||
func main() { | ||
nexServer = nex.NewServer() | ||
nexServer.SetPrudpVersion(1) | ||
nexServer.SetNexVersion(30701) | ||
nexServer.SetKerberosKeySize(32) | ||
nexServer.SetKerberosPassword(os.Getenv("KERBEROS_PASSWORD")) | ||
nexServer.SetAccessKey("d8927c3f") | ||
wg.Add(1) | ||
|
||
nexServer.On("Data", func(packet *nex.PacketV1) { | ||
request := packet.RMCRequest() | ||
// TODO - Add gRPC server | ||
go nex.StartNEXServer() | ||
|
||
fmt.Println("==MvDK:TS - Secure==") | ||
fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) | ||
fmt.Printf("Method ID: %#v\n", request.MethodID()) | ||
fmt.Println("==================") | ||
}) | ||
|
||
nexServer.On("Packet", func(packet *nex.PacketV1) { | ||
fmt.Println(packet.Type()) | ||
}) | ||
|
||
secureConnectionProtocol := secureconnection.NewCommonSecureConnectionProtocol(nexServer) | ||
|
||
secureConnectionProtocol.AddConnection(addConnection) // * Stubbed | ||
secureConnectionProtocol.UpdateConnection(updateConnection) // * Stubbed | ||
secureConnectionProtocol.DoesConnectionExist(doesConnectionExist) // * Stubbed | ||
|
||
secureConnectionProtocol.Register(register) // * Override the common handler becuase needs a specific format maybe? | ||
|
||
nexServer.Listen(":60041") | ||
wg.Wait() | ||
} |
Oops, something went wrong.