CITS 3002Computer NetworksAssignment: Socket ProgrammingDue date: Tuesday 8pm, 21 May 2019Drop dead due date: Friday 8pm, 24 May 2019 (10% penalty on raw grade per day)Worth: 20% of the whole gradeThis assignment is to expand the knowledge on socket programming. You are required to research further on socketprogramming in addition to the materials provided in this unit in order to complete the assignment. Please set asideenough time to finish this assignment rather than leaving it too late, as it will require some time to complete.1. Intro: Electronic Farce presents: RNG Battle RoyaleCongratulations! Youve been given an internship at one of the larger game developers, Electronic Farce,who have just launched yet another battle royale. The company intended all the interns to be concernedwith maintenance, testing and bug-fixing, but due to budget and time constraints a larger problem has arisen.**They forgot to implement a server**In a rather spectacular but not altogether surprising fashion, EF have tasked all of the interns (you) toimplement their server in a short period of time. Your task is to write a basic server in C, which adjudicatesand runs an RNG battle royale game. Of course, you will need to write some players (for example, in Python)to test your server as you go. We provide more specific game details below.2. The GameThe game in question is a rather simple dice game. A game consists of multiple rounds, all players start withsome (non-negative) number of lives. In each round, each player makes a guess on the outcome of the nextdice roll. The server rolls two dice. Players who correctly guess the outcome advance to the next roundwithout losing a life, while the rest lose a life. Players whose lives are reduced to zero are eliminated fromthe game. The last player remaining is deemed the victor. Figure 1 shows the game flow.The game playPlayers are given N lives (decided by the server. E.g. 3). Upon losing their lives they are knocked out of thegame. Given two six sided dice, players are allowed to make the following moves: Even - The sum of the two dice is an even number (excluding doubles) Odd - The sum of the two dice is an odd number greater than 5 Doubles - The two dice rolled are the same Contains N - At least one of the dice rolled in NIf the guess was incorrect, the player loses a life. If the player’s lives are reduced to zero, the player is out ofthe game.CITS 3002Computer NetworksFigure 1. Game flow (single game)Network RequirementsFor sake of simplicity we specify the format of packets to be sent below.Client to Server (the first field, %d, refers to client_id provided by the server). INIT %d,MOV,EVEN %d,MOV,ODD %d,MOV,DOUB %d,MOV,CON,%d int[1-6]Server to Client WELCOME,%d - Sent to acknowledge a connection, provide clients 3 digit ID START,%d,%d num_players, lives - Sent to notify that the game has begun %d,PASS - Sent to players who were correct %d,FAIL - Sent to players who were wrong %d,ELIM - Sent when a players lives are reduced to 0 VICT - Sent when no players are left REJECT - Sent to players trying to connect too late CANCEL - Sent when a game cannot startInitialise matchPlayer(s)life > 0?Wait forplayer(s) moveRoll diceCalculate scores Notify allplayersNotify all players of thecurrent standingNo YesExit gameCITS 3002Computer NetworksGame summary (repeated with networking)We can now describe the game-flow with respect to the packets sent between client and server.```Client->Server INIT if(allowed) Server->Client WELCOME else Server->Client REJECT, exit()// Some time will elapseif(enough_players) Server->All_Connected_Clients START,%d,%delse Server->All_Connect_Clients CANCEL, exit()while(true){ Client->Server MOV, EVEN||ODD||DOUB||CON,%d if(Server->Client PASS || FAIL) continue; elseif(Server->Client ELIM||VICT) exit()}```Packet DefinitionFor simplicity and consistency, we define the packet you should use below. It consists of: A character array of length `14`The structure comes from the limited cases allowed in the string.The client to server packets are of the form: INIT - Used to connect to a game %d1,MOV,EVEN||ODD||DOUB||CON,%d2 (%d1 client_id, %d2 being a 2 digit integer) -Representing a move in the gameThe server to client packets are of the form WELCOME,%d - Sent to a client if their connection is accepted, %d being a 3 digit client id. REJECT - Sent to a client if their connection rejected START,%d,%d (%d being a 2 digit integer) - Sent when a game has begun, the first number is thenumber of players in the match. The second is the number of lives you start with (can vary per game) CANCEL - Sent when not enough players join a match to begin %d,PASS - Sent to players whose moves are correct, %d client id %d,FAIL - Sent to players whose moves are incorrect, or failed to make a move. These players arestill in the game however, %d client_id %d,ELIM - Sent to players whose lives are depleted, %d client_id %d,VICT - Sent to the last remaining client (instead of a PASS or FAIL packet), %d client_idCITS 3002Computer NetworksEdge-casesIn the case of a draw (i.e. 2 players are removed simultaneously), then both players win.3. TasksYour goal is to implement a server in C which implements the game described above, then shuts-down. Clients connect to this server and are updated on game state and asked to make movesEmphasis is on the ability to start, maintain and tear-down connections in C versus optimisingnetwork performanceTo get started, you are provided with: basic_server.c - A basic server written in C. This is a starting point only, you are allowedto modify it as you see fit (we provide some starting suggestions). socket_client.py - A basic client written on Python. This is a starting point only to show howwe expect connections to be setup. You are expected to write your own clients while testing.To guide your efforts, we provide three tiers of tasks to complete. Solutions which meet Tier 1 requirementsare minimally viable, higher tiers offer more granulated mark allocations for solving more complex problems.We will only assess a single submitted implementation (i.e. the tiers stack on each other rather thanimplementing the requirements of each separately).Tier 1 - If everything works as you expectCITS 3002作业代做、Socket Programming作业代写、代做C++语言作业、c++编程设计作业调试 代Implement a basic server in C which plays a single game of our game with a single player and then tears itselfdown. All players are expected to behave themselves (only make legal moves) and connections are expectedto be fast and stable. Server can receive a client connection and send a game initialisation message Update the client that the game has started Receive moves from players (allowed a basic timeout for moves). If a player fails to make a move,they are eliminated from the game Updates game-state based on moves from players Updates players on the outcome of a round Is able to tear down a finished gameAssumptions: Players know the IP address and expected port number of the server.Tier 2 - Scaling upIn addition to all Tier 1 requirements: The server must be able to play a game with at least four players in a gameThe server must inform each player only about their own game state. CITS 3002Computer NetworksTier 3 - Connection issuesOf course, the world is not perfect. In addition to all Tier 1 requirements, the server must be able to handleunexpected network behaviour. The server handles players exiting mid-game The server must handle players attempting to join mid-game Server must not send game-state information to this playerAssumptions: If the winning player disconnects, behaviour is undefined.Tier 4 - Game logic extendedEven when network failures are considered, players can still behave badly. The server must handle incorrectly formed move packets gracefully This includes valid but impossible moves and must kick the cheating player from the game The server must wait for some reasonable amount of time (~30s) before starting a game. If the lobbydoes not fill in time (> 4 players connect) the match is cancelled and connections are torn-downgracefully4. ReportIn addition to your server code you must write a report to discuss the following items. How would you scale up your solution to handle many more clients? How could you deal with identical messages arriving simultaneously on the same socket? With reference to your project, what are some of the key differences between designing networkprograms, and other programs you have developed? What are the limitations of your current implementation (e.g. scale, performance, complexity)?In addition, if you are working as a group, report the contribution of each member of the team.Your report should include your name(s) and student ID number(s). It should be no more than 2 pages.5. SubmissionSubmit your server code and report on LMS by the deadline. If you are working in groups, only one memberof the group should submit the assignment.6. Additional resourcesYou may find socket programming tutorial useful to get started:http://www.tutorialspoint.com/unix_sockets/socket_server_example.htmCITS 3002Computer Networks7. RubricsCriteria Highly Satisfactory Satisfactory UnsatisfactoryTier 1 (40 marks) Satisfy allconditions oftier 1 tasks Game playwith a singleclient Code isreasonable toread with goodcommentsDemonstrated the ability toimplement all game featuresfor a single player Correctly implement allfunctionalities for tier 1tasks. Code is clearly legiblewith sufficient commentsto understand.Demonstrated the ability toimplement some gamefeatures for a single player Many functionalities fortier 1 tasks areimplemented. Code is clearly legiblewith limited comments tounderstand.Failed to demonstrate theability to implement a singleplayer Very few functionalitiesfor tier 1 tasks areimplemented. Code is not legiblewithout sufficientcomments tounderstand.Tier 2 (15 marks) Satisfy allconditions oftier 2 tasks Multiple (>4)players canplay at thesame timeDemonstrated the ability toimplement all game featuresfor multi-players Players up to 4 can jointhe game. Minimal performanceoverhead.Demonstrated the ability toimplement some gamefeatures for multi-players Players up to 4 can jointhe game. Some performanceoverhead.Failed to demonstrate theability to implement multiplayers Multi-players are notsupported. Massive performanceoverhead when playing.Tier 3 (15 marks) Satisfy allconditions oftier 3 tasks Handles playerjoining/exitingmid-gameDemonstrated the ability tohandle playersjoining/exiting the game Players can exit midgamewithoutinterrupting the server. Players must wait untilcurrent game finishes tojoin the game.Demonstrated the ability tohandle players joining orexiting the game Players can exit midgamewithoutinterrupting the server,or Players must wait untilcurrent game finishes tojoin the game.Failed to demonstrate theability to handle playersjoining/exiting the game Players exiting mid-gameinterrupts the server. Players joining mid-gameinterrupts the server.Tier 4 (10 marks) Satisfy allconditions oftier 4 tasks Handles illegalmoves Wait forplayers to joingameDemonstrated the ability toimplement fair play Cheating players aredistinguished andremoved. Wait appropriately forplayers to join the game.Demonstrated the ability toimplement some fair play Some cheating playersare distinguished andremoved. Has some waitingfeatures for players tojoin the game.Failed to demonstrate theability to implement fair play Cannot deal withcheating players. Waiting for players tojoin is not reasonable orimplemented.Report (20 marks) Answer fourkey questionsasked insection 4Demonstrated the ability towrite a comprehensivereport Detailed discussion forfour questions asked. Clear explanations andreasonable justificationsare provided. In-depth knowledge ofthe projectdemonstrated.Demonstrated the ability towrite a reasonable report Some discussion for fourquestions asked. Some explanations andreasonable justificationsare provided. Some knowledge of theproject demonstrated.Failed to demonstrate theability to write a report Failed to discuss the fourquestions asked. Vague or no explanationsand justifications areprovided. Not much knowledge ofthe projectdemonstrated.This project assignment is out of total 100 possible marks.转自:http://www.7daixie.com/2019050812414762.html
网友评论