Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Open Virtual Carcassonne Clone
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Jonathan Michalon
Open Virtual Carcassonne Clone
Commits
17f5e99d
Commit
17f5e99d
authored
May 29, 2019
by
Jonathan Michalon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix small network issues/inconsistencies all around
parent
644c5f35
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
13 deletions
+28
-13
clients/bot/src/main.vala
clients/bot/src/main.vala
+0
-6
libovccclient/src/ovccclient-client.vala
libovccclient/src/ovccclient-client.vala
+3
-1
libovccclient/src/ovccclient-server.vala
libovccclient/src/ovccclient-server.vala
+25
-6
No files found.
clients/bot/src/main.vala
View file @
17f5e99d
...
...
@@ -26,12 +26,6 @@ public class Bot : OVCCClient.Client
break
;
}
catch
(
OVCCClient
.
ServerError
.
NICKNAME_IN_USE
e1
)
{
player_suffix
++;
}
catch
(
OVCCClient
.
ServerError
.
MISSING_AUTHENTICATION
e2
)
{
leave
();
throw
e2
;
/* avoid infinite loop */
}
catch
(
Error
e3
)
{
leave
();
throw
e3
;
}
}
debug
(
"Logged in with player_suffix = %u"
,
player_suffix
);
...
...
libovccclient/src/ovccclient-client.vala
View file @
17f5e99d
...
...
@@ -110,12 +110,14 @@ namespace OVCCClient
public
bool
leave
()
throws
ServerError
{
debug
(
"Leaving..."
);
sigqueue
.
remove_all
();
if
(
game
!=
null
)
{
game
.
abort
();
}
if
(
server
.
is_connected
())
{
if
(
server
!=
null
&&
server
.
is_connected
())
{
server
.
disconnect_from
();
}
/* destroy server */
...
...
libovccclient/src/ovccclient-server.vala
View file @
17f5e99d
...
...
@@ -92,6 +92,7 @@ namespace OVCCClient
private
DataOutputStream
output
;
/* why the hell can't I use Thread<void> here but in new()?? */
private
unowned
Thread
<
bool
>
listen_loop_thread
=
null
;
private
int
listen_loop_running
=
0
;
private
Cancellable
?
listen_loop_cancel
=
null
;
private
unowned
Thread
<
bool
>
send_loop_thread
=
null
;
private
int
send_loop_running
=
0
;
...
...
@@ -137,17 +138,19 @@ namespace OVCCClient
* the object anymore. This allows the field to be changed (e.g. to null)
* without problem for us. */
var
cancellable
=
listen_loop_cancel
;
var
running
=
true
;
while
(
running
&&
!
cancellable
.
is_cancelled
())
{
while
(
AtomicInt
.
get
(
ref
listen_loop_running
)
>
0
&&
!
cancellable
.
is_cancelled
())
{
Message
?
msg
;
try
{
msg
=
Message
.
receive
(
input
,
cancellable
);
}
catch
(
IOError
.
CANCELLED
e
)
{
debug
(
"Listen loop cancelled"
);
break
;
}
catch
(
Error
e
)
{
warning
(
"error receiving data: %s"
,
e
.
message
);
critical
(
"Assuming broken channel, shutting down listen loop"
);
break
;
}
...
...
@@ -163,9 +166,12 @@ namespace OVCCClient
return
false
;
});
if
(
msg
.
message_type
==
MessageType
.
DISCONNECT
)
{
running
=
false
;
break
;
break
;
}
}
listen_loop_running
=
0
;
return
true
;
}
...
...
@@ -193,6 +199,7 @@ namespace OVCCClient
try
{
msg
.
send
(
output
,
cancellable
);
}
catch
(
IOError
.
CANCELLED
e
)
{
debug
(
"Send loop cancelled"
);
break
;
}
catch
(
Error
e
)
{
warning
(
"Trying to send message %s: %s"
,
msg
.
get_type
().
name
(),
e
.
message
);
...
...
@@ -206,6 +213,9 @@ namespace OVCCClient
return
false
;
});
}
send_loop_running
=
0
;
return
true
;
}
...
...
@@ -219,12 +229,16 @@ namespace OVCCClient
*/
public
async
Message
receive_type
(
MessageType
mtype
,
Cancellable
?
cancellable
=
null
)
throws
IOError
throws
ServerError
,
IOError
{
Message
msg
=
null
;
ulong
id
=
0
;
ulong
cancel_id
=
0
;
if
(
AtomicInt
.
get
(
ref
listen_loop_running
)
==
0
)
{
throw
new
ServerError
.
COMMUNICATION_FAILED
(
"Listen loop is not running"
);
}
if
(
cancellable
!=
null
)
{
cancel_id
=
cancellable
.
connect
(()
=>
{
cancel_id
=
0
;
...
...
@@ -293,6 +307,10 @@ namespace OVCCClient
throw
err
;
}
else
if
(
cancellable
!=
null
)
{
cancellable
.
set_error_if_cancelled
();
if
(
cancellable
.
is_cancelled
())
{
/* maybe not sufficient if already popped out */
send_loop_queue
.
remove
(
msg
);
}
}
return
true
;
...
...
@@ -318,6 +336,7 @@ namespace OVCCClient
output
=
new
DataOutputStream
(
connection
.
output_stream
);
listen_loop_cancel
=
new
Cancellable
();
send_loop_cancel
=
new
Cancellable
();
listen_loop_running
=
1
;
listen_loop_thread
=
new
Thread
<
bool
>.
try
(
"listen loop"
,
listen_loop
);
send_loop_running
=
1
;
send_loop_thread
=
new
Thread
<
bool
>.
try
(
"send loop"
,
send_loop
);
...
...
@@ -346,12 +365,12 @@ namespace OVCCClient
throws
ServerError
requires
(
connection
!=
null
)
{
if
(
listen_loop_cancel
!=
null
)
{
if
(
listen_loop_cancel
!=
null
&&
AtomicInt
.
get
(
ref
listen_loop_running
)
>
0
)
{
listen_loop_cancel
.
cancel
();
listen_loop_cancel
=
null
;
listen_loop_thread
.
join
();
}
if
(
send_loop_cancel
!=
null
)
{
if
(
send_loop_cancel
!=
null
&&
AtomicInt
.
get
(
ref
send_loop_running
)
>
0
)
{
send_loop_cancel
=
null
;
AtomicInt
.
set
(
ref
send_loop_running
,
0
);
send_loop_thread
.
join
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment