-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entrance.sol
53 lines (42 loc) · 1.33 KB
/
Entrance.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
pragma solidity >=0.4.21 <0.6.0;
//Code from 35C3 Junior CTF
import "./SafeMath.sol"; //https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol
contract Entrance {
using SafeMath for *;
mapping(address => uint256) public balances;
mapping(address => bool) public has_played;
uint256 pin;
event EntranceFlag(string server, string port);
event Win();
modifier legit(uint256 _pin) {
if (_pin == pin) _;
}
modifier onlyNewPlayer {
if (has_played[msg.sender] == false) _;
}
constructor(uint256 _pin) public {
pin = _pin;
}
function enter(uint256 _pin) public legit(_pin) {
balances[msg.sender] = 10;
has_played[msg.sender] = false;
}
function balanceOf(address _who) public view returns (uint256 balance) {
return balances[_who];
}
function gamble() public onlyNewPlayer {
require (balances[msg.sender] >= 10);
if ((block.number).mod(7) == 0) {
balances[msg.sender] = balances[msg.sender].add(10);
// Tell the sender he won!
msg.sender.call("You won!");
has_played[msg.sender] = true;
} else {
balances[msg.sender] = balances[msg.sender].sub(10);
}
}
function getFlag(string memory _server, string memory _port) public {
require (balances[msg.sender] > 300);
emit EntranceFlag(_server, _port);
}
}