Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BattleArena
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scherbaum Maximilian
BattleArena
Commits
ea00021f
Commit
ea00021f
authored
1 year ago
by
Busch Elias
Browse files
Options
Downloads
Patches
Plain Diff
Update: changed the while loop in server to a Thread to be able to stop the server.
parent
758a4250
No related branches found
Branches containing commit
No related tags found
4 merge requests
!54
Update: coreMaps.json (added new maps)
,
!39
Merge Request
,
!37
eb093: Added: All other important values like Health, player direction etc are...
,
!35
Update: Added more Stuff to be transported over the server.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/hdm_stuttgart/battlearena/Model/Multiplayer/Server.java
+21
-13
21 additions, 13 deletions
...e/hdm_stuttgart/battlearena/Model/Multiplayer/Server.java
with
21 additions
and
13 deletions
src/main/java/de/hdm_stuttgart/battlearena/Model/Multiplayer/Server.java
+
21
−
13
View file @
ea00021f
...
...
@@ -25,28 +25,38 @@ public class Server {
private
static
int
[]
cords
;
private
static
int
[]
returncords
=
{
enemyx
,
enemyy
,
playerID
};
private
boolean
started
=
false
;
private
static
String
ipaddress
=
"localhost"
;
/*
public static void main(String[] args) throws IOException { //main method for testing purposes
public
static
void
main
(
String
[]
args
)
throws
IOException
{
//main method for testing purposes
Server
server
=
new
Server
();
log
.
info
(
"server starting..."
);
server.start(
ipaddress,
4444);
}
*/
server
.
start
(
4444
);
}
public
void
startServer
()
throws
IOException
{
Server
server
=
new
Server
();
log
.
info
(
"server starting..."
);
server
.
start
(
"localhost"
,
4444
);
server
.
start
(
4444
);
}
public
void
start
(
String
host_ip
,
int
port
)
throws
IOException
{
public
void
start
(
int
port
)
throws
IOException
{
serverSocket
=
new
ServerSocket
(
port
);
log
.
info
(
"server started!"
);
started
=
true
;
while
(
true
){
new
ServerHandler
(
serverSocket
.
accept
()).
start
();
}
log
.
info
(
"server accepting Thread starting..."
);
Thread
serverThread
=
new
Thread
(()
->
{
while
(
true
)
{
try
{
new
ServerHandler
(
serverSocket
.
accept
()).
start
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
});
serverThread
.
start
();
log
.
info
(
"requests accepting Thread started!"
);
}
private
static
class
ServerHandler
extends
Thread
{
...
...
@@ -115,7 +125,6 @@ public class Server {
//set playerID:
returncords
[
2
]
=
2
;
}
}
...
...
@@ -157,7 +166,6 @@ public class Server {
public
boolean
isStarted
()
{
return
started
;
}
public
static
void
setIpaddress
(
String
ipaddress
)
{
Server
.
ipaddress
=
ipaddress
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment