-
Notifications
You must be signed in to change notification settings - Fork 3
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
53 changed files
with
1,114 additions
and
742 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func AddNewUser(pid uint32) { | ||
username := GetUsernameFromPID(pid) | ||
|
||
filter := bson.D{ | ||
{"pid", pid}, | ||
{"missed_calls", bson.A{""}}, | ||
{"username", username}, | ||
{"status", "unallowed"}, | ||
} | ||
|
||
_, err := usersCollection.InsertOne(context.TODO(), filter) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,21 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func AddPlayerSession(pid uint32, urls []string, ip string, port string) { | ||
filter := bson.D{ | ||
{"pid", pid}, | ||
{"urls", urls}, | ||
{"ip", ip}, | ||
{"port", port}, | ||
} | ||
|
||
_, err := sessionsCollection.InsertOne(context.TODO(), filter) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,5 @@ | ||
package database | ||
|
||
func ConnectAll() { | ||
connectMongo() | ||
} |
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,41 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"time" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
var mongoClient *mongo.Client | ||
var mongoContext context.Context | ||
var accountDatabase *mongo.Database | ||
var doorsDatabase *mongo.Database | ||
var pnidCollection *mongo.Collection | ||
var nexAccountsCollection *mongo.Collection | ||
var regionsCollection *mongo.Collection | ||
var usersCollection *mongo.Collection | ||
var sessionsCollection *mongo.Collection | ||
var callsCollection *mongo.Collection | ||
var tourneysCollection *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) | ||
|
||
accountDatabase = mongoClient.Database("pretendo") | ||
pnidCollection = accountDatabase.Collection("pnids") | ||
nexAccountsCollection = accountDatabase.Collection("nexaccounts") | ||
|
||
doorsDatabase = mongoClient.Database("doors") | ||
usersCollection = doorsDatabase.Collection("users") | ||
sessionsCollection = doorsDatabase.Collection("sessions") | ||
callsCollection = doorsDatabase.Collection("calls") | ||
|
||
sessionsCollection.DeleteMany(context.TODO(), bson.D{}) | ||
callsCollection.DeleteMany(context.TODO(), bson.D{}) | ||
} |
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 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func DeletePlayerSession(pid uint32) { | ||
filter := bson.D{ | ||
{"pid", pid}, | ||
} | ||
|
||
_, err := sessionsCollection.DeleteOne(context.TODO(), filter) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,27 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func DoesSessionExist(pid uint32) bool { | ||
var result bson.M | ||
filter := bson.D{ | ||
{"pid", pid}, | ||
} | ||
|
||
err := sessionsCollection.FindOne(context.TODO(), filter, options.FindOne()).Decode(&result) | ||
if err != nil { | ||
if err == mongo.ErrNoDocuments { | ||
return false | ||
} else { | ||
panic(err) | ||
} | ||
} else { | ||
return true | ||
} | ||
} |
Oops, something went wrong.