Skip to content

Commit 2347ce2

Browse files
committed
Merge branch 'dev'
2 parents 47bfa5e + 4aba96e commit 2347ce2

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

documentation/introduction.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Minds and Machines
22
## Connect 4 AI Program
33

4-
[**Download**](https://github.com/exoRift/mindsmachines-connect4/releases/tag/v1.0.0)
4+
[**Download**](https://github.com/exoRift/mindsmachines-connect4/releases/tag/v1.1.0)
5+
[**Observer**](https://exoRift.github.io/mindsmachines-connect4)
56

67
Welcome to the Minds and Machines Connect 4 moderator program.
78

@@ -13,7 +14,7 @@ Websocket is a web protocol (similar to HTTP) that allows a client to open a two
1314
Websocket URLs generally follow this structure: `ws://123.456.789.10:1234` where the first set of numbers is the IP address and the second number is the port.
1415

1516
## Running the server
16-
The server can be started by running the executable which can be downloaded [here](https://github.com/exoRift/mindsmachines-connect4/releases/tag/v1.0.0). By default, it will use port 5000. If port 5000 is taken, use the command line to run the file and you can supply a port number afterward to switch the port.
17+
The server can be started by running the executable which can be downloaded [here](https://github.com/exoRift/mindsmachines-connect4/releases/tag/v1.1.0). By default, it will use port 5000. If port 5000 is taken, use the command line to run the file and you can supply a port number afterward to switch the port.
1718

1819
> [!TIP]
1920
> If Windows gives you gripe, click "More Info" and then click "Run Anyway"

src/client/Main.jsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Main extends React.Component {
99

1010
state = {
1111
server: null,
12+
ip: null,
1213
currentGame: null,
1314
socket: null,
1415
games: [],
@@ -75,9 +76,20 @@ class Main extends React.Component {
7576
disabled={this.state.inputLocked}
7677
/>
7778

78-
<button className='connect' disabled={this.state.inputLocked}>Connect!</button>
79+
<button type='submit' className='connect' disabled={this.state.inputLocked}>Connect!</button>
80+
81+
<button type='submit' className='quickconnect' onClick={() => this.setInput('server')('localhost:5000')}>Quick Connect</button>
7982
</form>
8083
)}
84+
85+
{this.state.server
86+
? (
87+
<p className='ip'>
88+
<span>Server IP: </span>
89+
<span>{this.state.ip ?? 'Loading...'}</span>
90+
</p>
91+
)
92+
: null}
8193
</div>
8294
)
8395
}
@@ -87,7 +99,7 @@ class Main extends React.Component {
8799
this.setState({
88100
inputs: {
89101
...this.state.inputs,
90-
[field]: e.target.value
102+
[field]: typeof e === 'string' ? e : e.target.value
91103
}
92104
})
93105
}
@@ -115,6 +127,16 @@ class Main extends React.Component {
115127

116128
this.refreshGames(this.state.inputs.server)
117129
this.refreshInterval = setInterval(() => this.refreshGames(this.state.inputs.server), Main.refreshRate)
130+
131+
fetch(`http://${this.state.inputs.server}/ip`, {
132+
method: 'GET'
133+
})
134+
.then((res) => {
135+
if (!res.ok) throw Error()
136+
else return res.text()
137+
})
138+
.then((ip) => this.setState({ ip }))
139+
.catch(() => this.setState({ ip: 'UNKNOWN' }))
118140
} else throw Error()
119141
})
120142
.catch(() => alert('Could not connect to server!'))

src/client/styles/Main.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ button.connect {
7171
font-size: 3em;
7272
}
7373

74+
button.quickconnect {
75+
background: lightgray;
76+
margin-top: auto;
77+
font-size: 2.6em;
78+
}
79+
7480
.games {
7581
position: relative;
7682
display: flex;
@@ -136,6 +142,12 @@ button.create::before {
136142
line-height: 0.6;
137143
}
138144

145+
.ip {
146+
position: fixed;
147+
right: 1em;
148+
bottom: 0;
149+
}
150+
139151
@keyframes backgroundanim {
140152
from {
141153
background-position: 5em 5em;

src/server/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ const server = app.listen(PORT, () => {
3131
const {
3232
port
3333
} = server.address()
34-
3534
const interfaces = Object.values(os.networkInterfaces()).flat()
35+
const ip = `${interfaces.find((i) => !i.internal && i.family === 'IPv4').address}:${port}`
36+
37+
console.info('Server online listening at %s', ip)
3638

37-
console.info('Server online listening at http://%s:%s', interfaces.find((i) => !i.internal && i.family === 'IPv4').address, port)
39+
app.get('/ip', (req, res) => res.send(200, ip))
3840
})

0 commit comments

Comments
 (0)