” 辅导CSSE2310编程、 写作programming程序、 写作C++编程Prepared for s4518306. Do not distribute.The University of QueenslandSchool of Information Technology and Electrical EngineeringCSSE2310 – Semester 2 2020Assignment 3 (v1.1)Marks: 46Weighting: 33% of your overall assignment markDue: 23:59 30 October, 2020Student conductThis is an individual assignment. You should feel free to discuss general aspects of C programming andthe assignment specification with fellow students, including on Piazza. In general, questions like How shouldthe program behave if hthis happensi? would be safe, if they are seeking clarification on the specification.You must not actively help (or seek help from) other students with the actual design and coding of yourassignment solution. It is cheating to look at another students assignment code and it is cheating toallow your code to be seen or shared in printed or electronic form by others. All submitted codewill be subject to automated checks for plagiarism and collusion. If we detect plagiarism or collusion, formalmisconduct proceedings will be initiated against you, and those you cheated with. Thats right, if you shareyour code with a friend, both of you are in trouble.You may use code provided to you by the CSSE2310 teaching staff in this semester.Uploading or otherwise providing the assignment specification to a third party including onlinetutorial and contract cheating websites is considered misconduct. The university is aware of thesesites and they cooperate with us in misconduct investigations.The course coordinator reserves the right to conduct interviews with students about theirsubmissions, for the purposes of establishing genuine authorship. If you write your own code,you have nothing to fear from this process.In short – Dont risk it! If youre having trouble, seek help early from a member of the teaching staff.Dont be tempted to copy another students code or to use an online cheating service. You should read andunderstand the statements on student misconduct in the course profile and on the school web-site: https://www.itee.uq.edu.au/about_ITEE/policies/student-misconduct.htmlAimYour task is to write two programs (rpsserver and rpsclient) that allow a rock/paper/scissors tournamentto be played between an arbitrary number of game clients.The rpsserver acts as a game matchmaker, and listens for connections from clients – rpsclient. The serverintroduces clients to each other, these clients then play a series of games (a match) against each other. Aftereach match, the players report the result of that match back to the server (SPEC UPDATE: This sentenceclarified to refer to matches, not games).Your programs will use network sockets for communication, and the pthreads library for multi-threading.No additional processes may be created, and pipes are not to be used for inter-process communication. Yourprograms are not to create or read any files from the filesystem.1Prepared for s4518306. Do not distribute.rpsserverThe rpsserver program will take no arguments../rpsserverUpon starting, it will listen on an ephemeral port (its command port), and print that port number to stdout.Note: You should fflush(stdout) to ensure immediate output of the port number.The server listens for messages on the command port (see Message Table below for details). Possible messagesinclude Match request (MR) – a connecting client is requesting to be matched with an opponent. Match result (RESULT) – players report the result of their match back to the serverMatch RequestWhen a client connects to the server, it should send a match request in order to be matched up with an opponent.If a client connects and does not send a match request as its first message (or sends an invalid request), theserver should close that connection.Upon receiving a match request, the server chooses an opponent from those waiting and sends a MATCHmessage to each of them. The MATCH message identifies the match number, opponent name, and opponentport number. Match identifiers issued by the server should start from 1 and increment for each new match itcoordinates. Note that match identifiers can potentially be negative.Players should be paired up for matches in the order that they connect to a server. The server will onlysend a match message once enough players are available to play a match.If rpsserver receives a match request from a client that has the same name as a client already playing, itshould reply with a BADNAME message and close that connection. A client is considered to be playing from thetime they first send a (succesful) match request, up until they send a result message at the end of the matchthey requested.An example of this interaction is as follows:1. Barney sends a match request (and will be kept waiting since there arent enough players yet)2. Barney (another one) sends a match request (and will be rejected with a BADNAME message since anotherclient with that name is already playing)3. Wilma sends a match request4. rpsserver sends MATCH messages to Barney and Wilma5. Pebbles sends a match request (and will be kept waiting since there arent enough players yet)6. Dino sends a match request7. rpsserver sends MATCH messages to Pebbles and Dino8. . . .9. Barney and Wilma finish their match and send RESULT messages10. Barney sends a match request (and will be kept waiting since there arent enough players yet)11. . . .2Prepared for s4518306. Do not distribute.Match ResultOnce clients have finished their match, they should each send a RESULT message back to the server. Thismessage should be sent using the same connection over which the initial MATCH message was received.Once both players messages are received, the server should close the connections to the players and crosscheckthe received messages for correctness. A result message pair is valid if: both messages are RESULT messages their IDs match the one given to the players in the initial match request the server sent the match results are the sameIf the messages are invalid, the server should ignore the result of that match. Otherwise, updates its storedset of results. The connections to both players are then closed.Handling SIGHUPUpon receiving SIGUP, the server should output (to stdout), the match outcomes (win, lose, tie) of all clientswho have played a match. This output should be sorted in lexicographic order (i.e. the order used by strcmp())by client name. The output is terminated by a new line containing three – characters terminated with a newlinecharacter. An example output is as follows:Barney 2 5 1Betty 7 5 0Fred 10 2 0Wilma 7 3 1—SIGHUP must not terminate the server. It should keep handling match requests until terminated withSIGINT or SIGKILL.rpsserver ErrorsThe following error messages should be sent to stderr.Exit code Condition Message1 Incorrect number of arguments Usage: rpsserver3Prepared for s4518306. Do not distribute.rpsclientThe rpsclient program takes 3 arguments:./rpsclient client_name num_matches serverportWhere client_name is a string comprised strictly of alphanumeric characters ([a-z][A-Z][0-9]). No spaces orother special characters are permitted in client names. Further, the following strings (without quotes) arereserved and may not be used as player names: TIE ERRORIf rpsclient is started with an invalid name, then it should exit with the appropriate error message andcode (see below). num_matches is a positive non-zero integer indicating how many matches the client wishes to play serverport identifies the command port of the server (running on localhost – use IP address 127.0.0.1or getaddrinfo(localhost, …)).GameplayUpon starting, the rpsclient should create and listen on an ephemeral port. It should then proceed to completethe number of matches specified on its command line. For each match, the client should: Connect to the server command port with a match request message, and wait for a response from theserver Once a match message is received, connect to the opponent identified in that message, and play the match.A match is the best of 5 games, or (after 5 games and still having a tie) until one player has the lead (upto 20 games). For example, if the first five games are tied, then the winner of the next game wins thematch. If 20 games are played without breaking the tie, the result is a tie. At the end of a match, each player sends its result back to the servers command port via a RESULTmessage. Note that the client should not create a new server connection to send the result. It should usethe one it created at the start of the match to receive its opponents information. Wait for 50 milliseconds before attempting to play a new match (hint, the usleep() function is helpfulhere).If the client is unable to create a connection to the server or gets disconnected from the server at any pointin time. . . If it receives invalid input from its opponent or the server, that match is considered to be an errorSPEC CLARIFICATION: Bold phrases in the following paragraph to clarify behaviour ondisconnect or bad server messages.If the client is unable to create a connection to the server or gets disconnected from the server at anypoint in time, it should exit with an Invalid port error (see the Errors section below). If the client receivesinvalid input from its opponent or the server, that match is considered to be an error.SPEC CLARIFICATION: Agents should write their moves over the connection they initiatedto their opponent, and read opponent moves from the socket on which they listened for incoming4Prepared for s4518306. Do not distribute.connections. To avoid any doubt, ensure that your agent is able to play against the demo_rpsclientimplementation on moss.Once the client has completed the number of matches specified on its command line, it should output a listof the results of all of its matches, in the order they were played. Each line of output has the following form:match_id opponent resultwhere result is from this players point of view. For example:1 Barney LOST4 Wilma TIE6 Barney ERROR7 Betty WINmeans that this player lost against Barney in match 1, tied with Wilma in match 4, had match 6 against Barney end in an error (e.g. Barney quit unexpectedly or sent invalid messages), won against Betty in match 7Example match resultsThe following examples aim to clarify the logic around match results, the 5/20 game min/max limit, and tiedmatches. Player 1 wins 5 games – Player 1 wins the match Player 1 wins 2 games, Player 2 wins 3 games – Player 2 wins the match Player 1 wins 2 games, Player 2 wins 2 games, game 5 is a tie, Player 1 wins game 6 – Player 1 wins thematch Player 1 wins 2 games, Player 2 wins 2 games, games 5-20 are ties – Match result is a tierpsclient ErrorsThe following error messages should be sent to stderr.Exit code Condition Message0 Player completed matches succesfully1 Incorrect number of arguments Usage: rpsclient name matches port2 Invalid name Invalid name3 Invalid match count (e.g. non-integerargument)Invalid match count4 Invalid port number (e.g. non-integerargument, or unable to connect)Invalid port number5Prepared for s4518306. Do not distribute.Move GenerationPlayer agents issue pseudo-random moves. Upon agent startup (not the beginning of each match), agents areto initialise their random number seed using srand() with the following algorithmchar* agent_name;…int seed=0;for(int i=0; istrlen(agent_name); i++) {seed+=agent_name[i];}srand(seed);Moves by each agent are then generated randomly as follows.int move_val = rand() % 3;As with Assignment 2, it is critical that you initialise and generate random numbers in exactlythis manner so that your results can be auto-marked.Rock-Paper-Scissors RulesMove values are interpreted as follows:Move value Move0 ROCK1 PAPER2 SCISSORSIn game play, the following defines the winner of each game ROCK beats SCISSORS SCISSORS beats PAPER PAPER beats ROCKIf two players make the same move, the game result is a tie.6Prepared for s4518306. Do not distribute.MessagesDirection Format Detailplayer server MR:name:port Agent name is requesting a match, their opponentshould connect on port porte.g. MR:fred:57854 (Hi, Im fred. Id like to play.Im listening on port 57584)server player BADNAME Your name is already in use. Please go away andcome back with a new name.server player MATCH:match_id:opponent:port Server telling agent it has been paired with opponentname, who is listening on port port.match_id is a unique decimal integer identifier forthe match, which must sent back with the matchresult message.e.g. MATCH:37:Wilma:43765(Your opponent in match 37 is Wilma, listening onport 43765)player player MOVE:move A players movemove = ROCK|PAPER|SCISSORSe.g.MOVE:SCISSORSplayer server RESULT:match_id:result Inform the server of match result.match_id=match ID (decimal)result=winner name, orresult=TIE (for a tied match)result=ERROR (e.g. if the opponent disconnectedunexpectedly)e.g. RESULT:34:Barney (Barney won match 34)e.g. RESULT:14:ERROR (Match 14 ended with someerror)e.g. RESULT:76:TIE (Match 76 was a tie)Forbidden functionsYou are not to use poll(), select() or any other non-blocking IO functions in your submission.StyleYou must follow version 2.0.4 of the CSSE2310/COMP7306 C programming style guide available on the courseBlackBoard site.SubmissionYour submission must include all source and any other required files (in particular you must submit a Make-file). Do not submit compiled files (eg .o, compiled programs) or rules or map files. You may not create anysubdirectories in your submission. Such subdirectories will be removed prior to marking.7Prepared for s4518306. Do not distribute.Your program must compile with the make command. Your program must be compiled under gcc withat least the following switches: -pedantic -Wall -pthread -std=gnu99. You are not permitted to disablewarnings or use pragmas to hide them.If any errors result from the make command (i.e. an executable cannot be created), then you will receive0 marks for functionality (see below). Any code without academic merit will be removed from your programbefore compilation is attempted (and if compilation fails, you will receive 0 marks for functionality). Yourprogram must not invoke other programs or use non-standard headers/libraries.The marking tests will run make in a clean SVN checkout of your repository, and will expect to find thefollowing two programs rpsserver rpsclientYour assignment submission must be commited to your subversion repository under httpss://source.eait.uq.edu.au/svn/csse2310-sXXXXXXX/trunk/ass3Note: sXXXXXXX is your moss/UQ login ID.Your submission will be assessed by the contents of your SVN repository at the due date/time.Any subversion commits after the due date will be ignored. You must ensure that all files needed to compileand use your assignment (including a makefile) are committed and not just sitting in your working directory.Do not commit compiled files or binaries. You are strongly encouraged to check out a clean copy for testingpurposes. The late submission policy in the CSSE2310 Electronic Course Profile applies. Be familiar with it!MarksMarks will be awarded for functionality and style.Functionality (42 marks)Provided your code compiles (see above), you will earn functionality marks based on the number of featuresyour program correctly implements, as outlined below. Partial marks will be awarded for partially meetingthe functionality requirements. Not all features are of equal difficulty. If your program does not allowa feature to be tested then you will receive 0 marks for that feature, even if you claim to haveimplemented it. For example, if your program can never open a file, we can not determine if your program candetect hits correctly. The markers will make no alterations to your code (other than to remove code withoutacademic merit).Marks will be assigned in the following categories. Your server and player programs will be tested independently,so even if your server doesnt work you can still get marks for the player.rpsserver (22 marks)1. Program correctly handles invalid command lines [1 mark]2. Coordinate a single match between two clients [4 total] Correctly handle SIGHUP and required match result output (2 marks) Correctly detect duplicate player name and send BADNAME message (2 marks) Sub category marks to be advised8Prepared for s4518306. Do not distribute.3. Coordinate multiple matches between two clients [5 total] Correctly handle SIGHUP and required match result output (2 marks) sub-category marks to be advised4. Coordinate multiple matches between multiple clients [12 total] Correctly handle SIGHUP and required match result output (4 marks) sub-category marks to be advisedrpsclient (20 marks) Program correctly handles invalid command line arguments (1 marks) Program correctly handles early termination by opponent (2 marks) Program correctly handles BADNAME message from server (1 marks) Program correctly plays a single match against one other opponent (4 marks) Program correctly plays a multiple matches against one other opponent (4 marks) Program correctly plays a multiple matches against multiple other opponents (4 marks) Program correctly outputs result of all played matches upon exit (4 marks) sub-category marks to be advisedStyle (4 marks)For this assignment, style will be auto-marked only.Style marks will be calculated as follows: Let A be the number of style violations detected by style.sh plus the number of compilation warnings.Your style mark is simply: an automatic mark (MA = 4 0.8A), as reported by the style.sh tool on mossThe number of compilation warnings will be the total number of distinct warning lines reported during thecompilation process described above. The number of style guide violations refers to the number of violations ofversion 2.0.4 of the CSSE2310 C Programming Style Guide.A maximum of 5 violations will be penalised for each broad guideline area. The broad guideline areas areNaming, Comments, Braces, Whitespace, Indentation, Line Length and Overall. For naming violations, thepenalty will be one violation per offending name (not per use of the name).To satisfy layout related guidelines, you may wish to consider the indent(1) tool. Your style mark cannever be more than your functionality mark – this prevents the submission of well styled programs which dontmeet at least a minimum level of required functionality.You are encouraged to use the style.sh tool installed on moss to style check your code before submission.9Prepared for s4518306. Do not distribute.Total markLet F be the functionality mark for your assignment. S be the style mark for your assignment.Your total mark for the assignment will be:M = F + min{F, S}In other words, you cant get more marks for style than you do for functionality. Pretty code that doesnt workwill not be rewarded!Late PenaltiesLate penalties will apply as outlined in the course profile.Hints Use appropriate modularisation techniques to share common code between the server and the agentprograms Study and experiment with the example code provided in Weeks 9 and 10 on sockets and pthreads. Dontstart writing the server until you understand these examples! Draw yourself a diagram that shows the relationships between the server threads You can use netcat to talk to the server, or another agent…Demonstration / reference implementationA reference solution is available on moss in the following location:/local/courses/csse2310/resources/assignment3In this directory you will find: demo_rpsserver – an implementation of rpsserver demo_rpsclient – an implementation of rpsclient demo_rpsclient_{cheat|lie}_{win|lose|tie} – test clients that will either cheat (to win, lose or tie),or lie about the match result (win/lose/tie). This allows you to deterministically test the behaviour ofyour server in the case of inconsistent match results reports for example. Dont try playing two cheatingagents against each other, they will deadlock each waiting for their opponents move before sending theirown.10Prepared for s4518306. Do not distribute.Reverse engineering and misconductThese binaries are execute-only (non-readable) for students. You can run them (have to specify full path to thebinary), but cannot copy them, debug them and so on. In principle it is possible, although difficult, for you toget access to the binary, and run it through a reverse engineering tool to try and recover the source code, orsomething approximating it.First of all – if you think this will be an easier path to a solution than just doing the coding, then you arewrong! Please dont waste your time.Secondly – if you do manage to do it, then you deserve the marks for the assignment. However, under nocircumstances are you to share with others your method, or code recovered through this method- that will be considered misconduct.Finally, if you do manage to crack these binaries please disclose it to me privately (no repercussions forresponsible disclosure), and talk to us about joining the UQ Cyber Squad because we want your mad skillz.Specification UpdatesAny errors or omissions discovered in the assignment specification will be added here, and new versions releasedwith adequate time for students to respond prior to due date. Potential specification errors or omissions can bediscussed on Piazza or emailed to csse2310@helpdesk.eait.uq.edu.au.v1.1 Add reference to demo implementations available on moss Clarify that agents write moves to their outbound connection, and read opponent moves from their inbound(listening) socket Clarify agent behaviour in case of disconnectionor bad messages from server Add forbidden functions list Fix misleading space in Usage: messages Clarify game vs match in paragraph 2 of Aims section Fix example RESULT messages in message table (was MR) Add Hints section11如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。