-
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
1 parent
3256bc2
commit 75ae5fe
Showing
6 changed files
with
130 additions
and
32 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
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 +1,44 @@ | ||
package flaghandlerservice | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/sdslabs/katana/lib/mongo" | ||
"github.com/sdslabs/katana/types" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func submitFlag(value string, team types.CTFTeam) (bool, int) { | ||
flag, err := mongo.FetchFlag(value) | ||
var points int | ||
if err != nil { | ||
if flag.TeamID == team.Index { | ||
return false, 0 | ||
} | ||
submission := &types.Submission{} | ||
submission.ChallengeID = flag.ChallengeID | ||
submission.Flag = flag.Value | ||
submission.Submitter = team.Index //time of submission could also be stored | ||
if res, err := mongo.InsertOne(context.Background(), mongo.SubmissionsCollection, submission); err != nil { | ||
log.Println(err) | ||
return false, 0 | ||
} else { | ||
log.Println(res) | ||
} | ||
if res, err := mongo.FetchChallenge(flag.ChallengeID); err != nil { | ||
log.Println(err) | ||
return false, 0 | ||
} else { | ||
team.Score += res.Points | ||
points = res.Points | ||
} | ||
if err := mongo.UpdateOne(context.Background(), mongo.TeamsCollection, bson.M{"id": team.Index}, team, options.FindOneAndUpdate().SetUpsert(false)); err != nil { | ||
log.Println(err) | ||
return false, 0 | ||
} | ||
return true, points | ||
} | ||
return false, 0 | ||
} |
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,33 @@ | ||
package flaghandlerservice | ||
|
||
const ( | ||
ServiceFail = "Failed to start flag submision service" | ||
|
||
ServiceSuccess = "Flag Submission Service Started at port " | ||
|
||
Connected = "Connected to" | ||
|
||
ClosingError = "Failed to close\n" | ||
|
||
ReadError = "Connection Read error\n" | ||
|
||
InitInstruction = "Connected to Flag Submission Service\nInitiate your session by `init <teamName> <password>`\n" | ||
|
||
InvalidCommand = "Invalid Command\n" | ||
|
||
InvalidParams = "Invalid Login Parameters \n" | ||
|
||
TeamAlreadyExists = "Team is already Logged in\n" | ||
|
||
TeamConnected = "Team successfully connected,\n Enter flags to submit them\n" | ||
|
||
InvalidCreds = "Invalid Team Credentials\n" | ||
|
||
SubmitSuccess = "Flag submitted successfully, points: " | ||
|
||
InvalidFlag = "Invalid FLag\n" | ||
|
||
NoLogin = "Please login Team first \n" | ||
|
||
WriteError = "Failed To Write" | ||
) |
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