Simulation Engines TDA571|DIT030 Network programming
Tommaso Piazza
1
Simulation Engines TDA571|DIT030 Network programming Tommaso - - PowerPoint PPT Presentation
Simulation Engines TDA571|DIT030 Network programming Tommaso Piazza 1 Administrative stuff Next week NO LECTURES Mon 30/11 Wed 2/12 but I will put up some times for supervisions, no specific topic. Sign up if you fell your group
1
IDC | Interaction Design Collegium
2
IDC | Interaction Design Collegium
3
IDC | Interaction Design Collegium
4
IDC | Interaction Design Collegium
5
IDC | Interaction Design Collegium
server or peer-to-peer (or a combination)?
bandwidth, and packet loss that exist on the Internet?
programming techniques we will use. What differs from a small- scale and a massive-scale multiplayer game?
6
IDC | Interaction Design Collegium
7
IDC | Interaction Design Collegium
8
IDC | Interaction Design Collegium
they can meet, chat, and form games. This place is often called a “lobby”, and a lobby service is a middleware allowing for the creation of such lobbies.
high latency and high packet loss. This means that we will often be unable to send frequent updates of the object state to the players participating in a
position of the objects given their old position and velocity.
protect our game as well as the players from these. Security in multiplayer games is a whole lecture in itself (maybe even a whole course!), but we will just talk briefly about this subject.
9
IDC | Interaction Design Collegium
10
IDC | Interaction Design Collegium
11
IDC | Interaction Design Collegium
12
IDC | Interaction Design Collegium
13
IDC | Interaction Design Collegium
14
IDC | Interaction Design Collegium
15
IDC | Interaction Design Collegium
socket for the actual client-server communication
16
IDC | Interaction Design Collegium
17
IDC | Interaction Design Collegium
int sockfd, newsockfd, portno, clilen, n; struct sockaddr_in serv_addr, cli_addr; char buffer[256]; sockfd = socket(AF_INET, SOCK_STREAM, 0); // (1) bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(port_number); serv_addr.sin_addr.s_addr = INADDR_ANY; bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); // (2) listen(sockfd, 5); // (3) clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); // (4) bzero(buffer, 256); n = read(newsockfd, buffer, 255); // (5) printf("Message: %s\n", buffer);
18
IDC | Interaction Design Collegium
int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; sockfd = socket(AF_INET, SOCK_STREAM, 0); // (1) server = gethostbyname(server_name); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *) server->h_addr, (char *) &serv_addr.sin_addr.s_addr, server- >h_length); serv_addr.sin_port = htons(port_number); connect(sockfd, &serv_addr, sizeof(serv_addr)); // (2) fgets(buffer, 255, stdin); write(sockfd, buffer, strlen(buffer)); // (3)
19
IDC | Interaction Design Collegium
manage input and output from a number of sockets in a sequential way (select() allows you to wait for input/output on a set of sockets).
the clients and the connections simultaneously.
clients; this is however not very practical for a game server where clients co-exist in the same virtual world, so here it is better to assign individual threads to users.
20
IDC | Interaction Design Collegium
the transfer
delivery of all information sent over the socket
resending and reordering packets
protocol where information is sent in variable-sized chunks called datagrams
non-critical game information
SOCK STREAM when creating our socket. In addition, we use the sendto() and recvfrom() calls for sending and receiving datagrams, respectively.
21
IDC | Interaction Design Collegium
22
IDC | Interaction Design Collegium
hosts involved in the game and their communication structure and protocol
selected
The server may or may not be an active participant in the game itself.
interconnected computers instead of a single one.
Truly distributed system.
23
IDC | Interaction Design Collegium
24
IDC | Interaction Design Collegium
25
IDC | Interaction Design Collegium
26
IDC | Interaction Design Collegium
27
IDC | Interaction Design Collegium
management technique to filter out relevant information.
be implemented in software).
transactions (i.e. ask C whether A hit B). Can be difficult (but not impossible) to solve.
28
IDC | Interaction Design Collegium
29
IDC | Interaction Design Collegium
high lag, low bandwidth, and high packet loss. We need to come up with ways to provide a playable game despite this
by malicious users
participate in multiplayer games
30
IDC | Interaction Design Collegium
31
IDC | Interaction Design Collegium
play
point numbers, etc
specific client
32
IDC | Interaction Design Collegium
33
IDC | Interaction Design Collegium
workable solution that is used by a few games, but which results in slightly more complex network code than for just one connection
the features we need
34
IDC | Interaction Design Collegium
the same as TCP.
the order they were sent.
destination if they arrive and are not resent if they do not.
35
IDC | Interaction Design Collegium
36
IDC | Interaction Design Collegium
state (usually position and velocity) to avoid visible “pops”.
predict future behavior
difference to the old position vector
vector as well
37
IDC | Interaction Design Collegium
38
IDC | Interaction Design Collegium
parties on an insecure connection, but here each user has a public and a private key. A user’s public key is used to encode messages for a that user so that only the user himself can decode it using his private key.
message with a message authentication code (MAC) generated using a secure cryptographic hashing function
user to avoid Man-in-the-Middle attacks
39
IDC | Interaction Design Collegium
network
distributed entities living on the network and which support method invocations
state of a game object to control updates and relevance filtering
to call methods such as Player.Shoot(), Player.Run(), Player.Duck(), etc.
40
IDC | Interaction Design Collegium
41
IDC | Interaction Design Collegium
the Torque engine
protection
utilization
42
IDC | Interaction Design Collegium
43
IDC | Interaction Design Collegium
game object
the object survives the fault
unnecessary updates across the network
44
IDC | Interaction Design Collegium
45
IDC | Interaction Design Collegium
network architecture to choose is difficult: a single server can quickly become a bottleneck. Cluster architectures are common
users who want to gain an upper hand. Therefore, we must work hard to minimize possibilities of tampering with the client or the network traffic to cheat
unhappy customers we will get if the server goes down (planned or not). We have to deal with issues how to update (or “patch”) the game as well as the clients
46
IDC | Interaction Design Collegium
47
IDC | Interaction Design Collegium
48
IDC | Interaction Design Collegium
49
IDC | Interaction Design Collegium
50