Thread: [Cruce-commit] SF.net SVN: cruce:[17] C/trunk
Status: Beta
Brought to you by:
caiusb
|
From: <ca...@us...> - 2010-03-10 11:26:48
|
Revision: 17
http://cruce.svn.sourceforge.net/cruce/?rev=17&view=rev
Author: caiusb
Date: 2010-03-10 11:26:41 +0000 (Wed, 10 Mar 2010)
Log Message:
-----------
Am creat ierarhia de directoare si am pus Makefile-uri in pentru server si
client.
Added Paths:
-----------
C/trunk/client/
C/trunk/client/Makefile
C/trunk/client/client.c
C/trunk/client/client_lavinia.c
C/trunk/protocol/
C/trunk/protocol/protocol.c
C/trunk/protocol/protocol.h
Removed Paths:
-------------
C/trunk/.project
C/trunk/Server/
C/trunk/client.c
C/trunk/protocol.h
C/trunk/server.c
C/trunk/server.h
C/trunk/src/
Deleted: C/trunk/.project
===================================================================
--- C/trunk/.project 2010-03-09 22:18:55 UTC (rev 16)
+++ C/trunk/.project 2010-03-10 11:26:41 UTC (rev 17)
@@ -1,81 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>Cruce</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
- <triggers>clean,full,incremental,</triggers>
- <arguments>
- <dictionary>
- <key>?name?</key>
- <value></value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.append_environment</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
- <value>all</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.buildArguments</key>
- <value></value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.buildCommand</key>
- <value>make</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.buildLocation</key>
- <value>${workspace_loc:/Cruce/Debug}</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
- <value>clean</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.contents</key>
- <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
- <value>false</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.enableFullBuild</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
- <value>all</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.stopOnError</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
- <value>true</value>
- </dictionary>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.cdt.core.cnature</nature>
- <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
- <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
- </natures>
-</projectDescription>
Added: C/trunk/client/Makefile
===================================================================
--- C/trunk/client/Makefile (rev 0)
+++ C/trunk/client/Makefile 2010-03-10 11:26:41 UTC (rev 17)
@@ -0,0 +1,14 @@
+objects = client.o protocol.o
+
+client: $(objects)
+ cc -o client $(objects)
+
+client.o: client.c ../protocol/protocol.h
+ cc -c client.c
+
+protocol.o: ../protocol/protocol.h ../protocol/protocol.c
+ cc -c ../protocol/protocol.c
+
+clean:
+ rm -f $(objects)
+ rm -f client
Added: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c (rev 0)
+++ C/trunk/client/client.c 2010-03-10 11:26:41 UTC (rev 17)
@@ -0,0 +1,110 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+/*
+* aici partea nashpa e ca clientul depinde de server.
+* NOT OK! Clientul si serverul depind numai de protocol
+* si nu intre ele
+*/
+#include "../server/server.h"
+#include "../protocol/protocol.h"
+
+struct jucator player;
+
+int join_game() {
+ char message[1024];
+ char answer = 'n';
+ while (answer != 'y') {
+ printf("Join game? [y|n]");
+ scanf("%c%*c", &answer);
+ }
+ memset(message, 0, 1024);
+ sprintf(message, "%d %s", JOIN_GAME, player.nume);
+ write(player.sfd, &message, strlen(message));
+
+ memset(message, 0, 1024);
+ read(player.sfd, &message, 1024);
+ int code = decode_message(message);
+ printf("Received %s from server\n", message);
+ if (code == NACK)
+ return 0;
+ else if (code == ACK)
+ return 1;
+}
+
+int start_game() {
+ char message[1024];
+ char answer = 'n';
+ while (answer != 'y') {
+ printf("Start game? [y|n]");
+ scanf("%c%*c", &answer);
+ }
+
+ memset(message, 0, 1024);
+ sprintf(message, "%d", START_GAME);
+ write(player.sfd, &message, strlen(message));
+
+ memset(message, 0, 1024);
+ read(player.sfd, &message, 1024);
+ int code = decode_message(message);
+ printf("Received %s from server\n", message);
+ if (code == NACK)
+ return 0;
+ else if (code == ACK)
+ return 1;
+}
+
+/** adresa, port, nume **/
+int main(int argc, char *argv[]) {
+ if (argc != 4) {
+ printf("eroare la nr de argumente\n");
+ exit(1);
+ }
+
+ char ip[16]; //adresa IP a serverului
+ strcpy(ip, argv[1]);
+ int port = atoi(argv[2]); //portul serverului
+ strcpy(player.nume, argv[3]);
+
+ player.sfd = socket(PF_INET, SOCK_STREAM, 0);
+ if (player.sfd == -1) {
+ printf("eroare la crearea socketului\n");
+ exit(1);
+ }
+
+ struct sockaddr_in serverSocket;
+ memset(&serverSocket, 0, sizeof(struct sockaddr_in));
+ serverSocket.sin_family = AF_INET;
+ serverSocket.sin_port = htons(port);
+ if (inet_aton(ip, &serverSocket.sin_addr) == 0) {
+ printf("eroare la adresa ip\n");
+ exit(1);
+ }
+
+ if (connect(player.sfd, (struct sockaddr *) &serverSocket, sizeof(struct sockaddr_in)) == -1) {
+ printf("eroare la crearea conexinii\n");
+ close(player.sfd);
+ exit(1);
+ }
+
+ printf("Connected to server\n");
+
+ if (!join_game()) {
+ printf("couldn't join the game\n");
+ exit(1);
+ }
+ //wait for 4 messages about players
+ if(!start_game()) {
+ printf("couldn't start the game\n");
+ exit(1);
+ }
+ printf("Now we play. Next time.\n");
+
+ shutdown(player.sfd, SHUT_RDWR);
+ close(player.sfd);
+ return 0;
+}
Added: C/trunk/client/client_lavinia.c
===================================================================
--- C/trunk/client/client_lavinia.c (rev 0)
+++ C/trunk/client/client_lavinia.c 2010-03-10 11:26:41 UTC (rev 17)
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+int main(int argc, char *argv[])
+{
+ int sfd;
+ struct sockaddr_in addr;
+ char buf, ip[16], buf1[100], *name;
+ int port, n=0;
+
+ if (argc == 1)
+ {
+ strcpy(ip,"127.0.0.1");
+ port = 1100;
+ }
+ else
+ if (argc == 2)
+ {
+ printf("Usage %s [ip port]\n",argv[0]);
+ exit(1);
+ }
+ else
+ {
+ strcpy(ip,argv[1]);
+ port = atoi(argv[2]);
+ }
+
+ // creare socket
+ sfd = socket(PF_INET, SOCK_STREAM, 0);
+ if (sfd == -1)
+ {
+ perror("Error creating socket");
+ exit(1);
+ }
+
+ memset(&addr,0,sizeof(struct sockaddr_in));
+ addr.sin_family = AF_INET;
+
+ // transformare IP din Internet Standard dot notation in Network standard
+ if (inet_aton(ip,&addr.sin_addr) == -1)
+ {
+ perror("Invalid address");
+ exit(1);
+ }
+
+ // transformare adresa port in network byte order/ short (2 octeti)
+ addr.sin_port = htons(port);
+
+ // conectare la server
+ if (connect(sfd,(struct sockaddr *) &addr, sizeof(struct sockaddr_in)) == -1)
+ {
+ perror("Error connecting to server");
+ exit(1);
+ }
+
+ printf("Connected to server\n");
+
+ // JOIN THE GAME
+ //---citire de la tastatura a numelui
+ printf("Do you wish to join the game. If so, please type your name");
+ scanf("%s",name);
+
+ //---construire mesaj de join
+ strcpy(buf,"1 ");
+ strcat(buf,name);
+ strcat(buf," \n");
+
+ //---trimitere catre server
+ write(sfd,&buf,strlen(buf));
+
+ //---MESSAGE FROM THE SERVER
+ memset(&buf1,0,100);
+ while (read(sfd,&buf,1))
+ buf1[n++] = buf;
+ strcat(buf1,"\n");
+ printf("%s",buf1);
+
+ // START THE GAME
+ printf("Do you wish to start the game? If so, please press any key!")
+ while(read(0,&buf,1) == 0)
+ ;
+ strcpy(buf,"2 \n");
+ write(sfd,&buf,strlen(buf));
+
+ //---MESSAGE FROM THE SERVER
+ memset(&buf1,0,100);
+ n = 0;
+ while (read(sfd,&buf,1))
+ buf1[n++] = buf;
+ strcat(buf1,"\n");
+ printf("%s",buf1);
+
+ close(sfd);
+}
Deleted: C/trunk/client.c
===================================================================
--- C/trunk/client.c 2010-03-09 22:18:55 UTC (rev 16)
+++ C/trunk/client.c 2010-03-10 11:26:41 UTC (rev 17)
@@ -1,97 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-int main(int argc, char *argv[])
-{
- int sfd;
- struct sockaddr_in addr;
- char buf, ip[16], buf1[100], *name;
- int port, n=0;
-
- if (argc == 1)
- {
- strcpy(ip,"127.0.0.1");
- port = 1100;
- }
- else
- if (argc == 2)
- {
- printf("Usage %s [ip port]\n",argv[0]);
- exit(1);
- }
- else
- {
- strcpy(ip,argv[1]);
- port = atoi(argv[2]);
- }
-
- // creare socket
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd == -1)
- {
- perror("Error creating socket");
- exit(1);
- }
-
- memset(&addr,0,sizeof(struct sockaddr_in));
- addr.sin_family = AF_INET;
-
- // transformare IP din Internet Standard dot notation in Network standard
- if (inet_aton(ip,&addr.sin_addr) == -1)
- {
- perror("Invalid address");
- exit(1);
- }
-
- // transformare adresa port in network byte order/ short (2 octeti)
- addr.sin_port = htons(port);
-
- // conectare la server
- if (connect(sfd,(struct sockaddr *) &addr, sizeof(struct sockaddr_in)) == -1)
- {
- perror("Error connecting to server");
- exit(1);
- }
-
- printf("Connected to server\n");
-
- // JOIN THE GAME
- //---citire de la tastatura a numelui
- printf("Do you wish to join the game. If so, please type your name");
- scanf("%s",name);
-
- //---construire mesaj de join
- strcpy(buf,"1 ");
- strcat(buf,name);
- strcat(buf," \n");
-
- //---trimitere catre server
- write(sfd,&buf,strlen(buf));
-
- //---MESSAGE FROM THE SERVER
- memset(&buf1,0,100);
- while (read(sfd,&buf,1))
- buf1[n++] = buf;
- strcat(buf1,"\n");
- printf("%s",buf1);
-
- // START THE GAME
- printf("Do you wish to start the game? If so, please press any key!")
- while(read(0,&buf,1) == 0)
- ;
- strcpy(buf,"2 \n");
- write(sfd,&buf,strlen(buf));
-
- //---MESSAGE FROM THE SERVER
- memset(&buf1,0,100);
- n = 0;
- while (read(sfd,&buf,1))
- buf1[n++] = buf;
- strcat(buf1,"\n");
- printf("%s",buf1);
-
- close(sfd);
-}
Added: C/trunk/protocol/protocol.c
===================================================================
--- C/trunk/protocol/protocol.c (rev 0)
+++ C/trunk/protocol/protocol.c 2010-03-10 11:26:41 UTC (rev 17)
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "protocol.h"
+
+int decode_message(char *message) {
+ int code;
+
+ if (message[1] <= '9' && message[1] >= '0') {
+ code = atoi(message);
+ strcpy(message, message + 3);
+ } else {
+ code = atoi(message);
+ strcpy(message, message + 2);
+ }
+ /*
+ printf("Decoded this message:\n");
+ printf("code: %d\n", code);
+ printf("message: %s\n", message);
+ printf("---end---\n");
+ */
+ return code;
+}
+
+void pad(char *msg) {
+ int size = strlen(msg);
+ int i;
+ for (i=size;i<MSG_SIZE;i++)
+ msg[i] = PAD_CHAR;
+ msg[MSG_SIZE-1] = '\0';
+}
Added: C/trunk/protocol/protocol.h
===================================================================
--- C/trunk/protocol/protocol.h (rev 0)
+++ C/trunk/protocol/protocol.h 2010-03-10 11:26:41 UTC (rev 17)
@@ -0,0 +1,24 @@
+#ifndef __PROTOCOL_H__
+#define __PROTOCOL_H__
+
+#define MSG_SIZE 1024
+#define PAD_CHAR ' '
+
+#define JOIN_GAME 1
+#define ACK 2
+#define NACK 3
+#define INFO_MSG 4
+#define START_GAME 5
+#define SEND_CARDS 6
+#define BEGIN_BID 7
+#define BID_? 8
+#define BID 9
+#define HIT 10
+#define CARD_ANUNT 11
+
+#define DELIMITER " "
+
+int decode_message(char *message);
+void pad(char *msg);
+
+#endif /* __PROTOCOL_H__ */
Deleted: C/trunk/protocol.h
===================================================================
--- C/trunk/protocol.h 2010-03-09 22:18:55 UTC (rev 16)
+++ C/trunk/protocol.h 2010-03-10 11:26:41 UTC (rev 17)
@@ -1,18 +0,0 @@
-#ifndef __PROTOCOL_H__
-#define __PROTOCOL_H__
-
-#define JOIN_GAME 1
-#define ACK 2
-#define NACK 3
-#define INFO_MSG 4
-#define START_GAME 5
-#define SEND_CARDS 6
-#define BEGIN_BID 7
-#define BID_? 8
-#define BID 9
-#define HIT 10
-#define CARD_ANUNT 11
-
-int decode_message(char *message);
-
-#endif /* __PROTOCOL_H__ */
Deleted: C/trunk/server.c
===================================================================
--- C/trunk/server.c 2010-03-09 22:18:55 UTC (rev 16)
+++ C/trunk/server.c 2010-03-10 11:26:41 UTC (rev 17)
@@ -1,219 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-//Our libraries
-#include "server.h"
-#include "protocol.h"
-
-
-#define NUMAR_ECHIPE 2
-
-
- //Server related fields
-struct echipa echipe[NUMAR_ECHIPE];
-struct sockaddr_in serverSocketAddress;
-char serverIP[16];
-int serverPort;
-int server_sfd;
-char messageDelimiter[] = " ";
-FILE *outputInfo;// = stdout;
-FILE *outputError;// = stdout;
-
-void decodeMessage(char message[], struct jucator sender)
-{
-
- if(message == NULL)
- {
- informationMessage(outputError, "The message is NULL!");
- exit(1);
- }
-
- informationMessage(outputInfo, "Starting message decoding");
-
- //Starting to decode the message
- char *header = strtok(message, messageDelimiter);
-
- informationMessage(outputInfo, "header = %s" , header);
-
- if(header == NULL)
- {
- informationMessage(outputError,"Error at separating the message header!\n");
- exit(0);
- }
-
- char *rest = strtok(NULL, messageDelimiter);
-
- int messageType = atoi(header);
-
- if(messageType == 0)
- {
- informationMessage(outputError, "Error decoding the message header!\n");
- exit(0);
- }
- informationMessage(outputInfo, "Successful message header separation.\n");
-
- switch(messageType)
- {
- case JOIN_GAME:
- {
- int i;
- int j;
- for (i = 0; i < NUMAR_ECHIPE; i++)
- {
- if(echipe[i].jucatori_activi < JUCATORI_PER_ECHIPA)
- {
- echipe[i].jucatori[echipe[i].jucatori_activi++] = sender;
- }
- }
-
- if(i == NUMAR_ECHIPE)
- {
- sendNACKMessage(sender, "Nu mai sunt locuri!\n");
- }
-
- //sending an acknowledge message
- sendAckMessage(sender, "Cerere acceptata.\n");
-
-
- for (i = 0; i < NUMAR_ECHIPE; i++)
- {
- for (j = 0; j < echipe[i].jucatori_activi; j++)
- {
- //To sent information message to the rest of players
- }
- }
- break;
- }
- }
-
-}
-
-void sendAckMessage(struct jucator receiver, char message[])
-{
- //adding the header
- char buffer[100];
- sprintf(buffer, "%d %s", ACK, message);
-
- write(receiver.sfd, &message, strlen(message) * sizeof(char));
-}
-
-void sendNACKMessage(struct jucator receiver, char message[])
-{
- //adding header
- //adding the header
- char buffer[100];
- sprintf(buffer, "%d %s", NACK, message);
-
- write(receiver.sfd, &message, strlen(message) * sizeof(char));
-}
-
-void informationMessage(FILE *output, char message[])
-{
- fprintf(output, "%s", message);
-}
-
-
-void setUpServer(char ip[], int port)
-{
- printf("Starting to set up the server.\n");
- strcpy(serverIP, ip);
- serverPort = port;
-
- //Setting up the sever socket
- server_sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (server_sfd == -1)
- {
- perror("Error creating Server socket!\n");
- exit(1);
- }
- memset(&serverSocketAddress, 0, sizeof(struct sockaddr_in));
- serverSocketAddress.sin_family = AF_INET;
- if (inet_aton(serverIP, &serverSocketAddress.sin_addr) == 0)
- {
- perror("Address not valid!\n");
- exit(1);
- }
- serverSocketAddress.sin_port = htons(serverPort);
-
- if (bind(server_sfd, (struct server *) &serverSocketAddress, sizeof(struct sockaddr_in)) == -1)
- {
- perror("Error binding to address");
- exit(1);
- }
-
- printf("Server set up to IP address: %s and binded to port %d.\n", serverIP, serverPort);
-}
-
-void startListening(int server_sfd)
-{
- if (listen(server_sfd, 100) == -1)
- {
- perror("Error listening to socket");
- exit(1);
- }
- else
- {
- printf("Server starting to listen.\n");
- }
-}
-
-int acceptConnection(int socketFileDescriptor)
-{
- informationMessage(outputInfo, "Accepting a connection request");
- struct sockaddr_in in_conn;
- socklen_t socksize = sizeof(struct sockaddr_in);
-
- memset(&in_conn, 0, sizeof(struct sockaddr_in));
-
- int connFileDescriptor = accept(socketFileDescriptor, (struct sockaddr *) &in_conn, &socksize);
-
- if (connFileDescriptor == -1)
- {
- informationMessage(outputError, "Error accepting connection");
- exit(1);
- }
-
- /*
- char *c = sprintf("Received connection from: %s\n", inet_ntoa(in_conn.sin_addr.s_addr));
- informationMessage(outputInfo, c);*/
-
- return connFileDescriptor;
-}
-
-void cleanUp()
-{
- close(server_sfd);
-}
-
-int main()
-{
- outputInfo = stdout;
- outputError = stdout;
-
-
- setUpServer("127.0.0.1", 1100);
-
- startListening(server_sfd);
-
- int playersConnected = 0;
- while(playersConnected < MAX_JUCATORI)
- {
- //Accepting connections from players
- int playerFileDescriptor = acceptConnection(server_sfd);
-
- echipe[playersConnected / NUMAR_ECHIPE].jucatori[playersConnected % JUCATORI_PER_ECHIPA].sfd = playerFileDescriptor;
- char c[100];
- sprintf(c, "%d players connected.\n", playersConnected);
- informationMessage(outputInfo, c);
- playersConnected++;
- }
-
- informationMessage(outputInfo, "All players connected to the server.\n");
-
- close(server_sfd);
-
- return 0;
-}
Deleted: C/trunk/server.h
===================================================================
--- C/trunk/server.h 2010-03-09 22:18:55 UTC (rev 16)
+++ C/trunk/server.h 2010-03-10 11:26:41 UTC (rev 17)
@@ -1,40 +0,0 @@
-#ifndef __SERVER_H__
-#define __SERVER_H__
-
-#define MAX_JUCATORI 4
-#define MAX_CARTI 24
-#define CARTI_MANA 6
-#define JUCATORI_PER_ECHIPA 2
-
-/**
-Structura pentru o carte
-valoare - valoare cartii (0,2,3,4,10,11)
-culoare - culoarea (D,V,M,R - Duba, Verde, Mac si Rosu).
-**/
-struct carte {
- int valoare;
- char culoare;
-};
-
-/**
-Structura pentru un jucator
-**/
-struct jucator {
- struct carte carti[CARTI_MANA];
- int carti_ramase;
- char nume[20];
- int sfd; /* socket file descriptor */
-};
-
-/**
-Structura pentru o echipa de 2 jucatori
-**/
-struct echipa {
- struct jucator jucatori[JUCATORI_PER_ECHIPA];
- int jucatori_activi;
- int anunturi;
- int scor;
- struct carte carti_luate[MAX_CARTI];
-};
-
-#endif /* __SERVER_H__ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ca...@us...> - 2010-03-10 11:54:38
|
Revision: 18
http://cruce.svn.sourceforge.net/cruce/?rev=18&view=rev
Author: caiusb
Date: 2010-03-10 11:54:31 +0000 (Wed, 10 Mar 2010)
Log Message:
-----------
Am uitat sa pun serverul.
Added Paths:
-----------
C/trunk/server/
C/trunk/server/Makefile
C/trunk/server/server.c
C/trunk/server/server.h
C/trunk/server/server_dummy.c
Added: C/trunk/server/Makefile
===================================================================
--- C/trunk/server/Makefile (rev 0)
+++ C/trunk/server/Makefile 2010-03-10 11:54:31 UTC (rev 18)
@@ -0,0 +1,23 @@
+objects = server.o protocol.o
+
+server: $(objects)
+ cc -o server $(objects)
+
+client.o: server.c ../protocol/protocol.h
+ cc -c server.c
+
+protocol.o: ../protocol/protocol.h ../protocol/protocol.c
+ cc -c ../protocol/protocol.c
+
+#dummy server
+dummy: dummy.o
+ cc -o dummy server_dummy.o protocol.o
+
+
+dummy.o: server_dummy.c ../protocol/protocol.h
+ cc -c server_dummy.c
+
+clean:
+ rm -f $(objects)
+ rm -f server
+ rm -f dummy
Added: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c (rev 0)
+++ C/trunk/server/server.c 2010-03-10 11:54:31 UTC (rev 18)
@@ -0,0 +1,219 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+//Our libraries
+#include "server.h"
+#include "protocol.h"
+
+
+#define NUMAR_ECHIPE 2
+
+
+ //Server related fields
+struct echipa echipe[NUMAR_ECHIPE];
+struct sockaddr_in serverSocketAddress;
+char serverIP[16];
+int serverPort;
+int server_sfd;
+char messageDelimiter[] = " ";
+FILE *outputInfo;// = stdout;
+FILE *outputError;// = stdout;
+
+void decodeMessage(char message[], struct jucator sender)
+{
+
+ if(message == NULL)
+ {
+ informationMessage(outputError, "The message is NULL!");
+ exit(1);
+ }
+
+ informationMessage(outputInfo, "Starting message decoding");
+
+ //Starting to decode the message
+ char *header = strtok(message, messageDelimiter);
+
+ informationMessage(outputInfo, "header = %s" , header);
+
+ if(header == NULL)
+ {
+ informationMessage(outputError,"Error at separating the message header!\n");
+ exit(0);
+ }
+
+ char *rest = strtok(NULL, messageDelimiter);
+
+ int messageType = atoi(header);
+
+ if(messageType == 0)
+ {
+ informationMessage(outputError, "Error decoding the message header!\n");
+ exit(0);
+ }
+ informationMessage(outputInfo, "Successful message header separation.\n");
+
+ switch(messageType)
+ {
+ case JOIN_GAME:
+ {
+ int i;
+ int j;
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ {
+ if(echipe[i].jucatori_activi < JUCATORI_PER_ECHIPA)
+ {
+ echipe[i].jucatori[echipe[i].jucatori_activi++] = sender;
+ }
+ }
+
+ if(i == NUMAR_ECHIPE)
+ {
+ sendNACKMessage(sender, "Nu mai sunt locuri!\n");
+ }
+
+ //sending an acknowledge message
+ sendAckMessage(sender, "Cerere acceptata.\n");
+
+
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ {
+ for (j = 0; j < echipe[i].jucatori_activi; j++)
+ {
+ //To sent information message to the rest of players
+ }
+ }
+ break;
+ }
+ }
+
+}
+
+void sendAckMessage(struct jucator receiver, char message[])
+{
+ //adding the header
+ char buffer[100];
+ sprintf(buffer, "%d %s", ACK, message);
+
+ write(receiver.sfd, &message, strlen(message) * sizeof(char));
+}
+
+void sendNACKMessage(struct jucator receiver, char message[])
+{
+ //adding header
+ //adding the header
+ char buffer[100];
+ sprintf(buffer, "%d %s", NACK, message);
+
+ write(receiver.sfd, &message, strlen(message) * sizeof(char));
+}
+
+void informationMessage(FILE *output, char message[])
+{
+ fprintf(output, "%s", message);
+}
+
+
+void setUpServer(char ip[], int port)
+{
+ printf("Starting to set up the server.\n");
+ strcpy(serverIP, ip);
+ serverPort = port;
+
+ //Setting up the sever socket
+ server_sfd = socket(PF_INET, SOCK_STREAM, 0);
+ if (server_sfd == -1)
+ {
+ perror("Error creating Server socket!\n");
+ exit(1);
+ }
+ memset(&serverSocketAddress, 0, sizeof(struct sockaddr_in));
+ serverSocketAddress.sin_family = AF_INET;
+ if (inet_aton(serverIP, &serverSocketAddress.sin_addr) == 0)
+ {
+ perror("Address not valid!\n");
+ exit(1);
+ }
+ serverSocketAddress.sin_port = htons(serverPort);
+
+ if (bind(server_sfd, (struct server *) &serverSocketAddress, sizeof(struct sockaddr_in)) == -1)
+ {
+ perror("Error binding to address");
+ exit(1);
+ }
+
+ printf("Server set up to IP address: %s and binded to port %d.\n", serverIP, serverPort);
+}
+
+void startListening(int server_sfd)
+{
+ if (listen(server_sfd, 100) == -1)
+ {
+ perror("Error listening to socket");
+ exit(1);
+ }
+ else
+ {
+ printf("Server starting to listen.\n");
+ }
+}
+
+int acceptConnection(int socketFileDescriptor)
+{
+ informationMessage(outputInfo, "Accepting a connection request");
+ struct sockaddr_in in_conn;
+ socklen_t socksize = sizeof(struct sockaddr_in);
+
+ memset(&in_conn, 0, sizeof(struct sockaddr_in));
+
+ int connFileDescriptor = accept(socketFileDescriptor, (struct sockaddr *) &in_conn, &socksize);
+
+ if (connFileDescriptor == -1)
+ {
+ informationMessage(outputError, "Error accepting connection");
+ exit(1);
+ }
+
+ /*
+ char *c = sprintf("Received connection from: %s\n", inet_ntoa(in_conn.sin_addr.s_addr));
+ informationMessage(outputInfo, c);*/
+
+ return connFileDescriptor;
+}
+
+void cleanUp()
+{
+ close(server_sfd);
+}
+
+int main()
+{
+ outputInfo = stdout;
+ outputError = stdout;
+
+
+ setUpServer("127.0.0.1", 1100);
+
+ startListening(server_sfd);
+
+ int playersConnected = 0;
+ while(playersConnected < MAX_JUCATORI)
+ {
+ //Accepting connections from players
+ int playerFileDescriptor = acceptConnection(server_sfd);
+
+ echipe[playersConnected / NUMAR_ECHIPE].jucatori[playersConnected % JUCATORI_PER_ECHIPA].sfd = playerFileDescriptor;
+ char c[100];
+ sprintf(c, "%d players connected.\n", playersConnected);
+ informationMessage(outputInfo, c);
+ playersConnected++;
+ }
+
+ informationMessage(outputInfo, "All players connected to the server.\n");
+
+ close(server_sfd);
+
+ return 0;
+}
Added: C/trunk/server/server.h
===================================================================
--- C/trunk/server/server.h (rev 0)
+++ C/trunk/server/server.h 2010-03-10 11:54:31 UTC (rev 18)
@@ -0,0 +1,40 @@
+#ifndef __SERVER_H__
+#define __SERVER_H__
+
+#define MAX_JUCATORI 4
+#define MAX_CARTI 24
+#define CARTI_MANA 6
+#define JUCATORI_PER_ECHIPA 2
+
+/**
+Structura pentru o carte
+valoare - valoare cartii (0,2,3,4,10,11)
+culoare - culoarea (D,V,M,R - Duba, Verde, Mac si Rosu).
+**/
+struct carte {
+ int valoare;
+ char culoare;
+};
+
+/**
+Structura pentru un jucator
+**/
+struct jucator {
+ struct carte carti[CARTI_MANA];
+ int carti_ramase;
+ char nume[20];
+ int sfd; /* socket file descriptor */
+};
+
+/**
+Structura pentru o echipa de 2 jucatori
+**/
+struct echipa {
+ struct jucator jucatori[JUCATORI_PER_ECHIPA];
+ int jucatori_activi;
+ int anunturi;
+ int scor;
+ struct carte carti_luate[MAX_CARTI];
+};
+
+#endif /* __SERVER_H__ */
Added: C/trunk/server/server_dummy.c
===================================================================
--- C/trunk/server/server_dummy.c (rev 0)
+++ C/trunk/server/server_dummy.c 2010-03-10 11:54:31 UTC (rev 18)
@@ -0,0 +1,104 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "../server.h"
+#include "../protocol.h"
+
+int decode_message(char *message) {
+ int code;
+ if (message[1] <= '9' && message[1] >= '0') {
+ code = atoi(message);
+ strcpy(message, message + 3);
+ }
+ code = atoi(message);
+ strcpy(message, message + 2);
+ printf("Decoded this message:\n");
+ printf("code: %d\n", code);
+ printf("message: %s\n", message);
+ printf("---end---\n");
+ return code;
+}
+
+/** address, port **/
+int main(int argc, char *argv[]) {
+ char ip[16];
+ strcpy(ip, argv[1]); //adresa IP server
+ int port = atoi(argv[2]); //port server
+
+ int socketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (socketFD == -1) {
+ printf("error creating socket\n");
+ exit(1);
+ }
+
+ struct sockaddr_in serverSocket;
+ memset(&serverSocket, 0, sizeof(struct sockaddr_in));
+ serverSocket.sin_family = AF_INET;
+ serverSocket.sin_port = htons(port);
+ if (inet_aton(ip, &serverSocket.sin_addr) == 0) {
+ printf("error in ip address format\n");
+ exit(1);
+ }
+
+ if (bind(socketFD, (const struct sockaddr *) &serverSocket, sizeof(struct sockaddr_in)) == -1) {
+ printf("error binding\n");
+ close(socketFD);
+ exit(1);
+ }
+
+ if (listen(socketFD, 100) == -1) {
+ printf("error listening\n");
+ close(socketFD);
+ exit(1);
+ }
+
+ printf("Server up and running\n");
+
+ for (;;) {
+ struct sockaddr_in remoteSocket;
+ socklen_t socksize = sizeof(struct sockaddr_in);
+ memset(&remoteSocket, 0, sizeof(struct sockaddr_in));
+ int connectionFD = accept(socketFD, (struct sockaddr *) &remoteSocket, &socksize);
+ if (connectionFD < 0) {
+ printf("error accepting connection\n");
+ close(socketFD);
+ exit(1);
+ }
+
+ //printf("Received connection from: %s\n",inet_ntoa(remoteSocket.sin_addr));
+ char message[1024];
+
+ while(players < 4) {
+ memset(message, 0, 1024);
+ read(connectionFD, &message, 1024);
+ printf("%s\n", message);
+ int code = decode_message(message);
+ if (code == JOIN_GAME) {
+ printf("YEAH\n");
+ memset(message, 0, 1024);
+ strcpy(message, "2 ACK");
+ write(connectionFD, &message, strlen(message));
+ }
+
+ memset(message, 0, 1024);
+ read(connectionFD, &message, 1024);
+ printf("%s\n", message);
+ code = decode_message(message);
+ if (code == START_GAME) {
+ printf("YEAH\n");
+ memset(message, 0, 1024);
+ strcpy(message, "2 ACK");
+ write(connectionFD, &message, strlen(message));
+ }
+
+ shutdown(connectionFD, SHUT_RDWR);
+ close(connectionFD);
+ }
+
+ close(socketFD);
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ca...@us...> - 2010-03-11 20:02:52
|
Revision: 20
http://cruce.svn.sourceforge.net/cruce/?rev=20&view=rev
Author: caiusb
Date: 2010-03-11 20:02:46 +0000 (Thu, 11 Mar 2010)
Log Message:
-----------
Added a basic "wire frame" implementation of the server. It will be
implemented in detail later.
Modified Paths:
--------------
C/trunk/protocol/protocol.h
C/trunk/server/server.c
C/trunk/server/server.h
Added Paths:
-----------
C/trunk/server/server_alin.c
Modified: C/trunk/protocol/protocol.h
===================================================================
--- C/trunk/protocol/protocol.h 2010-03-10 12:07:15 UTC (rev 19)
+++ C/trunk/protocol/protocol.h 2010-03-11 20:02:46 UTC (rev 20)
@@ -22,3 +22,4 @@
void pad(char *msg);
#endif /* __PROTOCOL_H__ */
+
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-10 12:07:15 UTC (rev 19)
+++ C/trunk/server/server.c 2010-03-11 20:02:46 UTC (rev 20)
@@ -1,217 +1,139 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
-//Our libraries
#include "server.h"
-#include "../protocol/protocol.h"
-#define NUMAR_ECHIPE 2
+#define NUMAR_ECHIPE 2
- //Server related fields
-struct echipa echipe[NUMAR_ECHIPE];
-struct sockaddr_in serverSocketAddress;
-char serverIP[16];
-int serverPort;
-int server_sfd;
-char messageDelimiter[] = " ";
-FILE *outputInfo;// = stdout;
-FILE *outputError;// = stdout;
+struct echipa echipe[NUMAR_ECHIPE];
-void decodeMessage(char message[], struct jucator sender)
-{
+struct sockaddr_in addr;
+char ip[16];
+int port;
+int sfd;
- if(message == NULL)
- {
- informationMessage(outputError, "The message is NULL!");
- exit(1);
- }
-
- informationMessage(outputInfo, "Starting message decoding");
-
- //Starting to decode the message
- char *header = strtok(message, messageDelimiter);
-
- informationMessage(outputInfo, "header = %s" , header);
-
- if(header == NULL)
- {
- informationMessage(outputError,"Error at separating the message header!\n");
- exit(0);
- }
-
- char *rest = strtok(NULL, messageDelimiter);
-
- int messageType = atoi(header);
-
- if(messageType == 0)
- {
- informationMessage(outputError, "Error decoding the message header!\n");
- exit(0);
- }
- informationMessage(outputInfo, "Successful message header separation.\n");
-
- switch(messageType)
- {
- case JOIN_GAME:
+void init()
+{
+ int i, j;
+
+ for (i=0;i<NUMAR_ECHIPE;i++)
+ for (j=0;j<JUCATORI_PER_ECHIPA;j++)
{
- int i;
- int j;
- for (i = 0; i < NUMAR_ECHIPE; i++)
- {
- if(echipe[i].jucatori_activi < JUCATORI_PER_ECHIPA)
- {
- echipe[i].jucatori[echipe[i].jucatori_activi++] = sender;
- }
- }
-
- if(i == NUMAR_ECHIPE)
- {
- sendNACKMessage(sender, "Nu mai sunt locuri!\n");
- }
-
- //sending an acknowledge message
- sendAckMessage(sender, "Cerere acceptata.\n");
-
-
- for (i = 0; i < NUMAR_ECHIPE; i++)
- {
- for (j = 0; j < echipe[i].jucatori_activi; j++)
- {
- //To sent information message to the rest of players
- }
- }
- break;
+ echipe[i].jucatori[j].joined = 0;
+ echipe[i].jucatori[j].active = 0;
+ strcpy(echipe[i].jucatori[j].nume,"");
}
- }
-
}
-void sendAckMessage(struct jucator receiver, char message[])
+/** reads the config file and sets ip and port **/
+void readConfig()
{
- //adding the header
- char buffer[100];
- sprintf(buffer, "%d %s", ACK, message);
-
- write(receiver.sfd, &message, strlen(message) * sizeof(char));
+ strcpy(ip,"127.0.0.1");
+ port = 1100;
}
-void sendNACKMessage(struct jucator receiver, char message[])
+int makeSocket()
{
- //adding header
- //adding the header
- char buffer[100];
- sprintf(buffer, "%d %s", NACK, message);
-
- write(receiver.sfd, &message, strlen(message) * sizeof(char));
+ int s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s == -1)
+ {
+ perror("Eroare creare socket");
+ exit(EXIT_FAILURE);
+ }
}
-void informationMessage(FILE *output, char message[])
+void bindAndListen()
{
- fprintf(output, "%s", message);
-}
-
-
-void setUpServer(char ip[], int port)
-{
- printf("Starting to set up the server.\n");
- strcpy(serverIP, ip);
- serverPort = port;
-
- //Setting up the sever socket
- server_sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (server_sfd == -1)
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ if (inet_aton(ip, &addr.sin_addr) == -1)
{
- perror("Error creating Server socket!\n");
- exit(1);
+ perror("Invalid ip address");
+ exit(EXIT_FAILURE);
}
- memset(&serverSocketAddress, 0, sizeof(struct sockaddr_in));
- serverSocketAddress.sin_family = AF_INET;
- if (inet_aton(serverIP, &serverSocketAddress.sin_addr) == 0)
+
+ if (bind(sfd, &addr, sizeof(struct sockaddr_in)) == -1)
{
- perror("Address not valid!\n");
- exit(1);
+ perror("Error binding to address");
+ exit(EXIT_FAILURE);
}
- serverSocketAddress.sin_port = htons(serverPort);
-
- if (bind(server_sfd, (struct server *) &serverSocketAddress, sizeof(struct sockaddr_in)) == -1)
+
+ if (listen(sfd, 100) == -1)
{
- perror("Error binding to address");
- exit(1);
+ perror("Error listening to port");
+ exit(EXIT_FAILURE);
}
-
- printf("Server set up to IP address: %s and binded to port %d.\n", serverIP, serverPort);
}
-void startListening(int server_sfd)
+/* TODO aici se poate face ca sa nu se blocheze la accept, folosind select */
+int acceptConn(int sfd)
{
- if (listen(server_sfd, 100) == -1)
- {
- perror("Error listening to socket");
- exit(1);
- }
- else
- {
- printf("Server starting to listen.\n");
- }
-}
-
-int acceptConnection(int socketFileDescriptor)
-{
- informationMessage(outputInfo, "Accepting a connection request");
struct sockaddr_in in_conn;
socklen_t socksize = sizeof(struct sockaddr_in);
memset(&in_conn, 0, sizeof(struct sockaddr_in));
+
+ /* TODO print info message */
- int connFileDescriptor = accept(socketFileDescriptor, (struct sockaddr *) &in_conn, &socksize);
-
- if (connFileDescriptor == -1)
+ int fd = accept(sfd, (struct sockaddr *) &in_conn, &socksize);
+ if (fd == -1)
{
- informationMessage(outputError, "Error accepting connection");
- exit(1);
+ perror("Error accepting connection");
+ exit(EXIT_FAILURE);
}
- /*
- char *c = sprintf("Received connection from: %s\n", inet_ntoa(in_conn.sin_addr.s_addr));
- informationMessage(outputInfo, c);*/
+ return fd;
+}
- return connFileDescriptor;
+/* TODO */
+/** Returneaza true daca toti jucatorii au dat join game **/
+int joinGame()
+{
}
-void cleanUp()
+/* TODO */
+/** Returneaza true daca toti jucatorii au dat start game **/
+int startGame()
{
- close(server_sfd);
}
-int main()
+/* TODO */
+/** Ia un mesaj din retea si vede ce e cu el **/
+/* expected reprezinta un vector de int care specifica ce mesaje se
+ * se asteapta sa vina. Este terminat cu un 0. Daca nu vine un mesaj
+ * "expected" atunci el este ignorat (sau poate altceva)
+ * Daca expected este NULL atunci se iau in considerare toate mesajele */
+void getMSG(int *expected)
{
- outputInfo = stdout;
- outputError = stdout;
+}
-
- setUpServer("127.0.0.1", 1100);
-
- startListening(server_sfd);
-
- int playersConnected = 0;
- while(playersConnected < MAX_JUCATORI)
+int main(int argc, char *argv[])
+{
+ int noPlayers = 0;
+
+ init();
+
+ readConfig();
+
+ sfd = makeSocket();
+ bindAndListen();
+
+ while (noPlayers != MAX_JUCATORI)
{
- //Accepting connections from players
- int playerFileDescriptor = acceptConnection(server_sfd);
-
- echipe[playersConnected / NUMAR_ECHIPE].jucatori[playersConnected % JUCATORI_PER_ECHIPA].sfd = playerFileDescriptor;
- char c[100];
- sprintf(c, "%d players connected.\n", playersConnected);
- informationMessage(outputInfo, c);
- playersConnected++;
+ int fd = acceptConn(sfd);
+ echipe[noPlayers / NUMAR_ECHIPE].jucatori[noPlayers % JUCATORI_PER_ECHIPA].sfd = fd;
+ noPlayers ++;
+ /* TODO daca nu se blocheaza accept s-ar putea pune si aici un getMSG(...) ca se proceseze eventualele
+ * mesaje care au aparul (gen join game) */
}
-
- informationMessage(outputInfo, "All players connected to the server.\n");
-
- close(server_sfd);
-
- return 0;
+
+ while(!joinGame())
+ getMSG(NULL);
+
+ while(!startGame())
+ getMSG(NULL);
}
Modified: C/trunk/server/server.h
===================================================================
--- C/trunk/server/server.h 2010-03-10 12:07:15 UTC (rev 19)
+++ C/trunk/server/server.h 2010-03-11 20:02:46 UTC (rev 20)
@@ -23,7 +23,9 @@
struct carte carti[CARTI_MANA];
int carti_ramase;
char nume[20];
- int sfd; /* socket file descriptor */
+ int sfd; /* socket file descriptor */
+ int joined; /* daca jucatorul s-a alaturat jocului */
+ int active; /* daca jucatorul a inceput jocul */
};
/**
Added: C/trunk/server/server_alin.c
===================================================================
--- C/trunk/server/server_alin.c (rev 0)
+++ C/trunk/server/server_alin.c 2010-03-11 20:02:46 UTC (rev 20)
@@ -0,0 +1,217 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+//Our libraries
+#include "server.h"
+#include "../protocol/protocol.h"
+
+#define NUMAR_ECHIPE 2
+
+ //Server related fields
+struct echipa echipe[NUMAR_ECHIPE];
+struct sockaddr_in serverSocketAddress;
+char serverIP[16];
+int serverPort;
+int server_sfd;
+char messageDelimiter[] = " ";
+FILE *outputInfo;// = stdout;
+FILE *outputError;// = stdout;
+
+void decodeMessage(char message[], struct jucator sender)
+{
+
+ if(message == NULL)
+ {
+ informationMessage(outputError, "The message is NULL!");
+ exit(1);
+ }
+
+ informationMessage(outputInfo, "Starting message decoding");
+
+ //Starting to decode the message
+ char *header = strtok(message, messageDelimiter);
+
+ informationMessage(outputInfo, "header = %s" , header);
+
+ if(header == NULL)
+ {
+ informationMessage(outputError,"Error at separating the message header!\n");
+ exit(0);
+ }
+
+ char *rest = strtok(NULL, messageDelimiter);
+
+ int messageType = atoi(header);
+
+ if(messageType == 0)
+ {
+ informationMessage(outputError, "Error decoding the message header!\n");
+ exit(0);
+ }
+ informationMessage(outputInfo, "Successful message header separation.\n");
+
+ switch(messageType)
+ {
+ case JOIN_GAME:
+ {
+ int i;
+ int j;
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ {
+ if(echipe[i].jucatori_activi < JUCATORI_PER_ECHIPA)
+ {
+ echipe[i].jucatori[echipe[i].jucatori_activi++] = sender;
+ }
+ }
+
+ if(i == NUMAR_ECHIPE)
+ {
+ sendNACKMessage(sender, "Nu mai sunt locuri!\n");
+ }
+
+ //sending an acknowledge message
+ sendAckMessage(sender, "Cerere acceptata.\n");
+
+
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ {
+ for (j = 0; j < echipe[i].jucatori_activi; j++)
+ {
+ //To sent information message to the rest of players
+ }
+ }
+ break;
+ }
+ }
+
+}
+
+void sendAckMessage(struct jucator receiver, char message[])
+{
+ //adding the header
+ char buffer[100];
+ sprintf(buffer, "%d %s", ACK, message);
+
+ write(receiver.sfd, &message, strlen(message) * sizeof(char));
+}
+
+void sendNACKMessage(struct jucator receiver, char message[])
+{
+ //adding header
+ //adding the header
+ char buffer[100];
+ sprintf(buffer, "%d %s", NACK, message);
+
+ write(receiver.sfd, &message, strlen(message) * sizeof(char));
+}
+
+void informationMessage(FILE *output, char message[])
+{
+ fprintf(output, "%s", message);
+}
+
+
+void setUpServer(char ip[], int port)
+{
+ printf("Starting to set up the server.\n");
+ strcpy(serverIP, ip);
+ serverPort = port;
+
+ //Setting up the sever socket
+ server_sfd = socket(PF_INET, SOCK_STREAM, 0);
+ if (server_sfd == -1)
+ {
+ perror("Error creating Server socket!\n");
+ exit(1);
+ }
+ memset(&serverSocketAddress, 0, sizeof(struct sockaddr_in));
+ serverSocketAddress.sin_family = AF_INET;
+ if (inet_aton(serverIP, &serverSocketAddress.sin_addr) == 0)
+ {
+ perror("Address not valid!\n");
+ exit(1);
+ }
+ serverSocketAddress.sin_port = htons(serverPort);
+
+ if (bind(server_sfd, (struct server *) &serverSocketAddress, sizeof(struct sockaddr_in)) == -1)
+ {
+ perror("Error binding to address");
+ exit(1);
+ }
+
+ printf("Server set up to IP address: %s and binded to port %d.\n", serverIP, serverPort);
+}
+
+void startListening(int server_sfd)
+{
+ if (listen(server_sfd, 100) == -1)
+ {
+ perror("Error listening to socket");
+ exit(1);
+ }
+ else
+ {
+ printf("Server starting to listen.\n");
+ }
+}
+
+int acceptConnection(int socketFileDescriptor)
+{
+ informationMessage(outputInfo, "Accepting a connection request");
+ struct sockaddr_in in_conn;
+ socklen_t socksize = sizeof(struct sockaddr_in);
+
+ memset(&in_conn, 0, sizeof(struct sockaddr_in));
+
+ int connFileDescriptor = accept(socketFileDescriptor, (struct sockaddr *) &in_conn, &socksize);
+
+ if (connFileDescriptor == -1)
+ {
+ informationMessage(outputError, "Error accepting connection");
+ exit(1);
+ }
+
+ /*
+ char *c = sprintf("Received connection from: %s\n", inet_ntoa(in_conn.sin_addr.s_addr));
+ informationMessage(outputInfo, c);*/
+
+ return connFileDescriptor;
+}
+
+void cleanUp()
+{
+ close(server_sfd);
+}
+
+int main()
+{
+ outputInfo = stdout;
+ outputError = stdout;
+
+
+ setUpServer("127.0.0.1", 1100);
+
+ startListening(server_sfd);
+
+ int playersConnected = 0;
+ while(playersConnected < MAX_JUCATORI)
+ {
+ //Accepting connections from players
+ int playerFileDescriptor = acceptConnection(server_sfd);
+
+ echipe[playersConnected / NUMAR_ECHIPE].jucatori[playersConnected % JUCATORI_PER_ECHIPA].sfd = playerFileDescriptor;
+ char c[100];
+ sprintf(c, "%d players connected.\n", playersConnected);
+ informationMessage(outputInfo, c);
+ playersConnected++;
+ }
+
+ informationMessage(outputInfo, "All players connected to the server.\n");
+
+ close(server_sfd);
+
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ca...@us...> - 2010-03-12 15:18:59
|
Revision: 21
http://cruce.svn.sourceforge.net/cruce/?rev=21&view=rev
Author: caiusb
Date: 2010-03-12 15:18:46 +0000 (Fri, 12 Mar 2010)
Log Message:
-----------
Serverul merge pentru JOIN_GAME si START_GAME. Am adaugat o functie de unpad()
la protocol, dar nu merge inca. Se ocupa Alin de ea. Am modificat un pic
clientul sa trimita mesaje de 1024 de bytes, nu strlen(msg). Asta doar ca
sa mearga la rulare, so you just override the changes.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/protocol/protocol.c
C/trunk/protocol/protocol.h
C/trunk/server/server.c
C/trunk/server/server.h
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-11 20:02:46 UTC (rev 20)
+++ C/trunk/client/client.c 2010-03-12 15:18:46 UTC (rev 21)
@@ -24,7 +24,9 @@
}
memset(message, 0, 1024);
sprintf(message, "%d %s", JOIN_GAME, player.nume);
- write(player.sfd, &message, strlen(message));
+ pad(message);
+ printf("%s\n",message);
+ write(player.sfd, &message, MSG_SIZE);
memset(message, 0, 1024);
read(player.sfd, &message, 1024);
@@ -46,7 +48,8 @@
memset(message, 0, 1024);
sprintf(message, "%d", START_GAME);
- write(player.sfd, &message, strlen(message));
+ pad(message);
+ write(player.sfd, &message, MSG_SIZE);
memset(message, 0, 1024);
read(player.sfd, &message, 1024);
@@ -103,8 +106,8 @@
exit(1);
}
printf("Now we play. Next time.\n");
-
- shutdown(player.sfd, SHUT_RDWR);
+
+ //shutdown(player.sfd, SHUT_RDWR);
close(player.sfd);
return 0;
}
Modified: C/trunk/protocol/protocol.c
===================================================================
--- C/trunk/protocol/protocol.c 2010-03-11 20:02:46 UTC (rev 20)
+++ C/trunk/protocol/protocol.c 2010-03-12 15:18:46 UTC (rev 21)
@@ -6,6 +6,8 @@
int decode_message(char *message) {
int code;
+ unpad(message);
+
if (message[1] <= '9' && message[1] >= '0') {
code = atoi(message);
strcpy(message, message + 3);
@@ -29,3 +31,13 @@
msg[i] = PAD_CHAR;
msg[MSG_SIZE-1] = '\0';
}
+
+void unpad(char *msg)
+{
+ int i = strlen(msg) - 1;
+ for (;i>=0;i--)
+ if (msg[i] != ' ')
+ break;
+
+ msg[i+1] = '\0';
+}
Modified: C/trunk/protocol/protocol.h
===================================================================
--- C/trunk/protocol/protocol.h 2010-03-11 20:02:46 UTC (rev 20)
+++ C/trunk/protocol/protocol.h 2010-03-12 15:18:46 UTC (rev 21)
@@ -20,6 +20,7 @@
int decode_message(char *message);
void pad(char *msg);
+void unpad(char *msg);
#endif /* __PROTOCOL_H__ */
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-11 20:02:46 UTC (rev 20)
+++ C/trunk/server/server.c 2010-03-12 15:18:46 UTC (rev 21)
@@ -6,6 +6,7 @@
#include <netinet/in.h>
#include "server.h"
+#include "../protocol/protocol.h"
#define NUMAR_ECHIPE 2
@@ -74,16 +75,26 @@
{
struct sockaddr_in in_conn;
socklen_t socksize = sizeof(struct sockaddr_in);
+ int fd = 0;
+ fd_set set;
+ struct timeval t;
memset(&in_conn, 0, sizeof(struct sockaddr_in));
- /* TODO print info message */
-
- int fd = accept(sfd, (struct sockaddr *) &in_conn, &socksize);
- if (fd == -1)
+ FD_ZERO(&set);
+ FD_SET(sfd, &set);
+ t.tv_sec = 0;
+ t.tv_usec = 0;
+
+ select(sfd+1,&set,NULL,NULL,&t);
+ if (FD_ISSET(sfd,&set))
{
- perror("Error accepting connection");
- exit(EXIT_FAILURE);
+ fd = accept(sfd, (struct sockaddr *) &in_conn, &socksize);
+ if (fd == -1)
+ {
+ perror("Error accepting connection");
+ exit(EXIT_FAILURE);
+ }
}
return fd;
@@ -101,14 +112,106 @@
{
}
+/** deal with case when a player leaves **/
+void leave_game()
+{
+ printf("Player left\n");
+ exit(EXIT_SUCCESS);
+}
+
/* TODO */
/** Ia un mesaj din retea si vede ce e cu el **/
/* expected reprezinta un vector de int care specifica ce mesaje se
* se asteapta sa vina. Este terminat cu un 0. Daca nu vine un mesaj
* "expected" atunci el este ignorat (sau poate altceva)
* Daca expected este NULL atunci se iau in considerare toate mesajele */
-void getMSG(int *expected)
+void getMSG(struct jucator *jucator, int *expected)
{
+ fd_set set;
+ int i, j, max = 0;
+ struct timeval t;
+ int fd;
+ char msg[MSG_SIZE];
+
+ t.tv_sec = 0;
+ t.tv_usec = 0;
+
+ do
+ {
+ FD_ZERO(&set);
+ for (i=0; i<NUMAR_ECHIPE; i++)
+ for (j=0; j<JUCATORI_PER_ECHIPA; j++)
+ {
+ FD_SET(echipe[i].jucatori[j].sfd,&set);
+ if (max < echipe[i].jucatori[j].sfd)
+ max = echipe[i].jucatori[j].sfd;
+ }
+
+ select(max+1,&set,NULL,NULL,&t);
+ if (jucator != NULL)
+ if (!FD_ISSET(jucator->sfd,&set))
+ {
+ // send NACK
+ }
+ else
+ {
+ fd = jucator->sfd;
+ break;
+ }
+ else
+ {
+ int bla = 0;
+ /* TODO multiple messages received */
+ for (i=0; i<NUMAR_ECHIPE; i++)
+ for (j=0; j<JUCATORI_PER_ECHIPA; j++)
+ if (FD_ISSET(echipe[i].jucatori[j].sfd,&set))
+ {
+ fd = echipe[i].jucatori[j].sfd;
+ bla = 1;
+ }
+ if (!bla)
+ return; /* daca nu a venit mesaj ies din functie */
+ else
+ break; /* daca a venit il tratez */
+ }
+ }
+ while(1);
+
+ /* a venit mesajul de la cine trebe */
+ int read_rt;
+
+ read_rt = read(fd,&msg,MSG_SIZE);
+ if (read_rt == 0)
+ {
+ printf("Connection closed\n");
+ leave_game();
+ }
+ if (read_rt != MSG_SIZE);
+ printf("Warning: too few bytes read\n");
+
+ printf("%s\n",msg);
+ //scanf("%*c");
+
+ int code = decode_message(msg);
+ char resp[MSG_SIZE];
+
+ /* TODO remove! */
+ sprintf(resp,"%d",ACK);
+ pad(resp);
+
+ switch(code)
+ {
+ case JOIN_GAME:
+ printf("%s joined the game\n",msg);
+ write(fd,resp,MSG_SIZE);
+ break;
+ case START_GAME:
+ printf("%s started the game\n",msg);
+ write(fd,resp,MSG_SIZE);
+ break;
+ default:
+ printf("Wrong message!\n");
+ }
}
int main(int argc, char *argv[])
@@ -125,15 +228,19 @@
while (noPlayers != MAX_JUCATORI)
{
int fd = acceptConn(sfd);
- echipe[noPlayers / NUMAR_ECHIPE].jucatori[noPlayers % JUCATORI_PER_ECHIPA].sfd = fd;
- noPlayers ++;
- /* TODO daca nu se blocheaza accept s-ar putea pune si aici un getMSG(...) ca se proceseze eventualele
- * mesaje care au aparul (gen join game) */
+ int ex_msg[] = {JOIN_GAME,START_GAME,0};
+ if (fd != 0)
+ {
+ printf("Accepted player\n");
+ echipe[noPlayers / NUMAR_ECHIPE].jucatori[noPlayers % JUCATORI_PER_ECHIPA].sfd = fd;
+ noPlayers ++;
+ }
+ getMSG(NULL,ex_msg);
}
while(!joinGame())
- getMSG(NULL);
+ getMSG(NULL,NULL);
while(!startGame())
- getMSG(NULL);
+ getMSG(NULL,NULL);
}
Modified: C/trunk/server/server.h
===================================================================
--- C/trunk/server/server.h 2010-03-11 20:02:46 UTC (rev 20)
+++ C/trunk/server/server.h 2010-03-12 15:18:46 UTC (rev 21)
@@ -33,7 +33,6 @@
**/
struct echipa {
struct jucator jucatori[JUCATORI_PER_ECHIPA];
- int jucatori_activi;
int anunturi;
int scor;
struct carte carti_luate[MAX_CARTI];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-13 09:16:51
|
Revision: 25
http://cruce.svn.sourceforge.net/cruce/?rev=25&view=rev
Author: alinposho
Date: 2010-03-13 09:16:45 +0000 (Sat, 13 Mar 2010)
Log Message:
-----------
Modified Paths:
--------------
C/trunk/server/Object/server
Property Changed:
----------------
C/trunk/
C/trunk/client/
Property changes on: C/trunk
___________________________________________________________________
Modified: svn:ignore
- Debug
.cproject
+ Debug
.cproject
.project
Property changes on: C/trunk/client
___________________________________________________________________
Added: svn:ignore
+ client
Modified: C/trunk/server/Object/server
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-13 10:22:35
|
Revision: 30
http://cruce.svn.sourceforge.net/cruce/?rev=30&view=rev
Author: alinposho
Date: 2010-03-13 10:22:29 +0000 (Sat, 13 Mar 2010)
Log Message:
-----------
Added Paths:
-----------
C/trunk/BuildAll.sh
C/trunk/CleanAll.sh
Added: C/trunk/BuildAll.sh
===================================================================
--- C/trunk/BuildAll.sh (rev 0)
+++ C/trunk/BuildAll.sh 2010-03-13 10:22:29 UTC (rev 30)
@@ -0,0 +1,40 @@
+
+#First cleanup
+./CleanAll.sh
+
+
+#Creeam protocol
+protocolFolder=./protocol/
+protocolMakefile=Makefile
+
+echo "Building protocol"
+cd $protocolFolder
+make -f $protocolMakefile
+cd ..
+
+
+
+#Creeam server
+serverFolder=./server/
+serverMakefile=Makefile
+
+echo "Building server"
+
+cd $serverFolder
+make -f $serverMakefile
+cd ..
+
+
+
+#Creeam client
+clientFolder=./client/
+clientMakefile=Makefile
+
+echo "Building client"
+
+cd $clientFolder
+make -f $clientMakefile
+cd ..
+
+
+
Property changes on: C/trunk/BuildAll.sh
___________________________________________________________________
Added: svn:executable
+ *
Added: C/trunk/CleanAll.sh
===================================================================
--- C/trunk/CleanAll.sh (rev 0)
+++ C/trunk/CleanAll.sh 2010-03-13 10:22:29 UTC (rev 30)
@@ -0,0 +1,17 @@
+
+#Stergem fisierele executabile si obiect
+
+#ale clientului
+clientObjectFolder=./client/Object
+echo "Stergem fisierele din folder $clientObjectFolder"
+rm -f $clientObjectFolder/*
+
+#din protocol
+protocolObjectFolder=./protocol/Object
+echo "Stergem fisierele din folder $protocolObjectFolder"
+rm -f $protocolObjectFolder/*
+
+#din protocol
+serverObjectFolder=./server/Object
+echo "Stergem fisierele din folder $serverObjectFolder"
+rm -f $serverObjectFolder/*
Property changes on: C/trunk/CleanAll.sh
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-13 10:26:11
|
Revision: 32
http://cruce.svn.sourceforge.net/cruce/?rev=32&view=rev
Author: alinposho
Date: 2010-03-13 10:26:05 +0000 (Sat, 13 Mar 2010)
Log Message:
-----------
Added Paths:
-----------
C/trunk/client/Object/
C/trunk/protocol/Object/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-03-13 16:45:33
|
Revision: 36
http://cruce.svn.sourceforge.net/cruce/?rev=36&view=rev
Author: horiaradu
Date: 2010-03-13 16:45:25 +0000 (Sat, 13 Mar 2010)
Log Message:
-----------
Am adus clientul pana la pasul 5 inclusiv; am integrat modificarile facute de mine si de Lavinia.
Am facut modificarile propuse la protocol, introducand cele 3 noi coduri.
Clientul nu este inca functional, asamblarea sa efectiva urmand sa o facem mai tarziu.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/protocol/protocol.c
C/trunk/protocol/protocol.h
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-13 11:17:25 UTC (rev 35)
+++ C/trunk/client/client.c 2010-03-13 16:45:25 UTC (rev 36)
@@ -10,26 +10,41 @@
* NOT OK! Clientul si serverul depind numai de protocol
* si nu intre ele
*/
-#include "../server/server.h"
+#include "client.h"
#include "../protocol/protocol.h"
struct jucator player;
+void showCards() {
+ int i;
+ printf("Carti: ");
+ for (i = 0; i < player.carti_ramase; i++)
+ printf("%s ", player.carti[i].simbol);
+ printf("\n");
+}
+
+void deleteCard(int card) {
+ int i;
+ for (i = card; i < player.carti_ramase - 1; i++)
+ player.carti[i] = player.carti[i+1];
+ player.carti_ramase--;
+}
+
int join_game() {
- char message[1024];
+ char message[MSG_SIZE];
char answer = 'n';
while (answer != 'y') {
printf("Join game? [y|n]");
scanf("%c%*c", &answer);
}
- memset(message, 0, 1024);
+ memset(message, 0, MSG_SIZE);
sprintf(message, "%d %s", JOIN_GAME, player.nume);
pad(message);
- printf("%s\n",message);
write(player.sfd, &message, MSG_SIZE);
- memset(message, 0, 1024);
- read(player.sfd, &message, 1024);
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ unpad(message);
int code = decode_message(message);
printf("Received %s from server\n", message);
if (code == NACK)
@@ -38,21 +53,36 @@
return 1;
}
+int waitAllPlayers() {
+ char message[MSG_SIZE];
+ int i;
+ for (i = 3; i > 0; i--) {
+ printf("%d more players to join the game...\n", i);
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ int code = decode_message(message);
+ if (code == INFO_MSG)
+ printf("%s\n",message);
+ }
+ return 1;
+}
+
int start_game() {
- char message[1024];
+ char message[MSG_SIZE];
char answer = 'n';
while (answer != 'y') {
printf("Start game? [y|n]");
scanf("%c%*c", &answer);
}
- memset(message, 0, 1024);
+ memset(message, 0, MSG_SIZE);
sprintf(message, "%d", START_GAME);
pad(message);
write(player.sfd, &message, MSG_SIZE);
- memset(message, 0, 1024);
- read(player.sfd, &message, 1024);
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ unpad(message);
int code = decode_message(message);
printf("Received %s from server\n", message);
if (code == NACK)
@@ -61,6 +91,196 @@
return 1;
}
+struct carte decodeCard(char *value, char *color) {
+ struct carte result;
+ result.culoare = color[0];
+ result.valoare = atoi(value);
+ if (result.valoare == 11)
+ strcpy(result.simbol, "A");
+ else if (result.valoare == 0)
+ strcpy(result.simbol, "9");
+ else
+ strcpy(result.simbol, value);
+ sprintf(result.simbol, "%s %c", result.simbol, color[0]);
+ return result;
+}
+
+int receiveCards() {
+ char message[MSG_SIZE];
+
+ player.carti_ramase = 0;
+
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ unpad(message);
+
+ char cardString[MSG_SIZE];
+ strcpy(cardString, message);
+
+ int code = decode_message(message);
+ if (code != SEND_CARDS)
+ return 1;
+
+ int i;
+ strtok(cardString, " ");
+ for (i = 0; i < 6; i++) {
+ char *value = strtok(NULL, " ");
+ char *color = strtok(NULL, " ");
+ if (value != NULL && color != NULL)
+ player.carti[player.carti_ramase++] = decodeCard(value, color);
+ else
+ return 1;
+ }
+ return 0;
+}
+
+int accept_cards() {
+ char message[MSG_SIZE];
+
+ memset(message, 0, MSG_SIZE);
+ sprintf(message,"%d ", ACK);
+ pad(message);
+ write(player.sfd, &message, MSG_SIZE);
+
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+
+ int code = decode_message(message);
+ if (code == BEGIN_BID)
+ return 1;
+ return 0;
+}
+
+int reject_cards() {
+ char message[MSG_SIZE];
+
+ memset(message, 0, MSG_SIZE);
+ sprintf(message,"%d ", NACK);
+ pad(message);
+ write(player.sfd, &message, MSG_SIZE);
+
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+
+ int code = decode_message(message);
+ if (code == ACK) // odata cu trimiterea ACK-ului serverul trimite si cartile => send_cards()
+ return 0; // trebuie apelat receive_cards pentru a le primi
+ else if (code == NACK) // odata cu neacceptarea refuzului jucatorului de a primi cartile, acesta este indreptat spre bid
+ return 1;
+}
+
+int bidding() {
+ char message[MSG_SIZE];
+
+ int ok = 0;
+ while (!ok) {
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ unpad(message);
+ int code = decode_message(message);
+
+ if (code == INFO_MSG)
+ printf("%s\n", message);
+
+ else if (code == BID) {
+ int bid = 0;
+ do {
+ printf("Cate faci? [0, 1, 2, 3, 4, 5, 6]\n");
+ scanf("%d%*c", &bid);
+ } while (bid < 0 || bid > 6);
+
+ memset(message, 0, MSG_SIZE);
+ sprintf(message, "%d %d", BID_RESP, bid);
+ pad(message);
+ write(player.sfd, &message, MSG_SIZE);
+ }
+ else if (code == END_BID) {
+ printf("castigator: %s", message);
+ ok = 1;
+ }
+
+ }
+
+ return 1;
+}
+
+int hand() {
+ char message[MSG_SIZE];
+
+ int endHand = 0;
+ int canAnnounce = 1;
+ while (!endHand) {
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ unpad(message);
+
+ int code = decode_message(message);
+ if (code == INFO_MSG) {
+ printf("%s\n", message);
+ canAnnounce = 0;
+ }
+ else if (code == HIT && canAnnounce == 0) {
+ int ok = 0;
+ while (!ok) {
+ int card = 0;
+
+ showCards();
+
+ do {
+ printf("Da carte! (index-ul cartii 0->5)\n");
+ scanf("%d%*c", &card);
+ } while (card < 0 || card >= player.carti_ramase);
+
+ memset(message, 0, MSG_SIZE);
+ sprintf(message, "%d %d %c", CARD, player.carti[card].valoare, player.carti[card].culoare);
+ pad(message);
+ write(player.sfd, &message, MSG_SIZE);
+
+ read(player.sfd, &message, MSG_SIZE);
+ unpad(message);
+ int code2 = decode_message(message);
+ if (code2 == ACK) {
+ ok = 1;
+ deleteCard(card);
+ } else if (code2 == NACK)
+ printf("Ceva nu e bine, mai da o data!");
+ }
+ }
+ else if (code == HIT && canAnnounce == 1) {
+ int ok = 0;
+ while (!ok) {
+ int card = 0, anunt = 0;
+
+ showCards();
+
+ do {
+ printf("Da carte + anunt daca ai! (index-ul cartii 0->5)\n");
+ scanf("%d %d%*c", &card, &anunt);
+ } while (card < 0 || card >= player.carti_ramase);
+
+ memset(message, 0, MSG_SIZE);
+ sprintf(message, "%d %d %c %d", CARD_ANUNT, player.carti[card].valoare, player.carti[card].culoare, anunt);
+ pad(message);
+ write(player.sfd, &message, MSG_SIZE);
+
+ read(player.sfd, &message, MSG_SIZE);
+ unpad(message);
+ int code2 = decode_message(message);
+ if (code2 == ACK) {
+ ok = 1;
+ deleteCard(card);
+ } else if (code2 == NACK)
+ printf("Ceva nu e bine, mai da o data!");
+ }
+ }
+ else if (code == END_HAND) {
+ printf("%s\n", message);
+ endHand = 1;
+ }
+ }
+ return 1;
+}
+
/** adresa, port, nume **/
int main(int argc, char *argv[]) {
if (argc != 4) {
@@ -101,11 +321,34 @@
exit(1);
}
//wait for 4 messages about players
+ waitAllPlayers();
+
+
if(!start_game()) {
printf("couldn't start the game\n");
exit(1);
}
- printf("Now we play. Next time.\n");
+
+ char opt = ' ', ok = 0;
+ while (!ok) {
+ if (!receiveCards()) {
+ printf("couldn't receive cards\n");
+ exit(1);
+ }
+
+ do {
+ showCards();
+ printf("Do you like your cards? y|n");
+ scanf("%c", opt);
+ if (opt == 'y')
+ ok = accept_cards();
+ else if (opt == 'n')
+ ok = reject_cards();
+ } while(opt != 'y' && opt != 'n');
+ }
+
+ bidding();
+ hand();
//shutdown(player.sfd, SHUT_RDWR);
close(player.sfd);
Modified: C/trunk/protocol/protocol.c
===================================================================
--- C/trunk/protocol/protocol.c 2010-03-13 11:17:25 UTC (rev 35)
+++ C/trunk/protocol/protocol.c 2010-03-13 16:45:25 UTC (rev 36)
@@ -15,19 +15,17 @@
code = atoi(message);
strcpy(message, message + 2);
}
- /*
printf("Decoded this message:\n");
printf("code: %d\n", code);
printf("message: %s\n", message);
printf("---end---\n");
- */
return code;
}
void pad(char *msg) {
int size = strlen(msg);
int i;
- for (i=size;i<MSG_SIZE;i++)
+ for (i = size; i < MSG_SIZE; i++)
msg[i] = PAD_CHAR;
msg[MSG_SIZE-1] = '\0';
}
@@ -35,7 +33,7 @@
void unpad(char *msg)
{
int i = strlen(msg) - 1;
- for (;i>=0;i--)
+ for (; i >= 0; i--)
if (msg[i] != ' ')
break;
Modified: C/trunk/protocol/protocol.h
===================================================================
--- C/trunk/protocol/protocol.h 2010-03-13 11:17:25 UTC (rev 35)
+++ C/trunk/protocol/protocol.h 2010-03-13 16:45:25 UTC (rev 36)
@@ -11,8 +11,8 @@
#define START_GAME 5
#define SEND_CARDS 6
#define BEGIN_BID 7
-#define BID_? 8
-#define BID 9
+#define BID 8
+#define BID_RESP 9
#define HIT 10
#define CARD_ANUNT 11
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <hor...@us...> - 2010-03-16 12:48:03
|
Revision: 38
http://cruce.svn.sourceforge.net/cruce/?rev=38&view=rev
Author: horiaradu
Date: 2010-03-16 12:47:56 +0000 (Tue, 16 Mar 2010)
Log Message:
-----------
Am bagat ultimele modificari facute de Lavinia, si mesajul START_ROUND care sa se trimita la inceputul unei runde.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/protocol/protocol.h
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-13 16:49:02 UTC (rev 37)
+++ C/trunk/client/client.c 2010-03-16 12:47:56 UTC (rev 38)
@@ -204,7 +204,7 @@
return 1;
}
-int hand() {
+int hands() {
char message[MSG_SIZE];
int endHand = 0;
@@ -273,7 +273,7 @@
printf("Ceva nu e bine, mai da o data!");
}
}
- else if (code == END_HAND) {
+ else if (code == END_ROUND) {
printf("%s\n", message);
endHand = 1;
}
@@ -281,6 +281,65 @@
return 1;
}
+void round() {
+ char opt = ' ', ok = 0;
+
+ while (!ok) {
+ if (!receiveCards()) {
+ printf("couldn't receive cards\n");
+ exit(1);
+ }
+
+ do {
+ showCards();
+ printf("Do you like your cards? y|n");
+ scanf("%c", opt);
+ if (opt == 'y')
+ ok = accept_cards();
+ else if (opt == 'n')
+ ok = reject_cards();
+ } while(opt != 'y' && opt != 'n');
+ }
+
+ bidding();
+
+ hands();
+}
+
+void score() {
+
+ char message[MSG_SIZE];
+
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, message, MSG_SIZE);
+ unpad(message);
+ int code = decode_message(message);
+
+ if (code == INFO_MSG)
+ printf("%s\n", message);
+}
+
+void game() {
+ char message[MSG_SIZE];
+ int code;
+
+ do {
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, message, MSG_SIZE);
+ unpad(message);
+ code = decode_message(message);
+
+ if (code == START_ROUND) {
+ round();
+ score(); // the score for the 2 teams
+ }
+ } while (code == START_ROUND);
+
+ printf("The game ended!");
+ printf("%s\n", message); // the score for the 2 teams
+}
+
+
/** adresa, port, nume **/
int main(int argc, char *argv[]) {
if (argc != 4) {
@@ -329,26 +388,7 @@
exit(1);
}
- char opt = ' ', ok = 0;
- while (!ok) {
- if (!receiveCards()) {
- printf("couldn't receive cards\n");
- exit(1);
- }
-
- do {
- showCards();
- printf("Do you like your cards? y|n");
- scanf("%c", opt);
- if (opt == 'y')
- ok = accept_cards();
- else if (opt == 'n')
- ok = reject_cards();
- } while(opt != 'y' && opt != 'n');
- }
-
- bidding();
- hand();
+ game();
//shutdown(player.sfd, SHUT_RDWR);
close(player.sfd);
Modified: C/trunk/protocol/protocol.h
===================================================================
--- C/trunk/protocol/protocol.h 2010-03-13 16:49:02 UTC (rev 37)
+++ C/trunk/protocol/protocol.h 2010-03-16 12:47:56 UTC (rev 38)
@@ -17,9 +17,10 @@
#define CARD_ANUNT 11
//propunere de extindere a protocolului:
-#define END_HAND 12
+#define END_ROUND 12
#define END_BID 13
#define CARD 14
+#define START_ROUND 15
#define DELIMITER " "
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ca...@us...> - 2010-03-17 08:35:25
|
Revision: 40
http://cruce.svn.sourceforge.net/cruce/?rev=40&view=rev
Author: caiusb
Date: 2010-03-17 08:35:18 +0000 (Wed, 17 Mar 2010)
Log Message:
-----------
Modified the CleanAll script so that it removes the Object folder.
Removed Object folder from version control
Modified Paths:
--------------
C/trunk/CleanAll.sh
Removed Paths:
-------------
C/trunk/client/Object/
C/trunk/server/Object/
Modified: C/trunk/CleanAll.sh
===================================================================
--- C/trunk/CleanAll.sh 2010-03-16 19:49:41 UTC (rev 39)
+++ C/trunk/CleanAll.sh 2010-03-17 08:35:18 UTC (rev 40)
@@ -15,3 +15,8 @@
serverObjectFolder=./server/Object
echo "Stergem fisierele din folder $serverObjectFolder"
rm -f $serverObjectFolder/*
+
+echo "Stergem pe Object"
+rmdir $clientObjectFolder
+rmdir $serverObjectFolder
+rmdir $protocolObjectFolder
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ca...@us...> - 2010-03-17 08:40:00
|
Revision: 41
http://cruce.svn.sourceforge.net/cruce/?rev=41&view=rev
Author: caiusb
Date: 2010-03-17 08:39:54 +0000 (Wed, 17 Mar 2010)
Log Message:
-----------
Modified BuildAll to create the Object folders.
Modified Paths:
--------------
C/trunk/BuildAll.sh
Removed Paths:
-------------
C/trunk/protocol/Object/
Modified: C/trunk/BuildAll.sh
===================================================================
--- C/trunk/BuildAll.sh 2010-03-17 08:35:18 UTC (rev 40)
+++ C/trunk/BuildAll.sh 2010-03-17 08:39:54 UTC (rev 41)
@@ -2,6 +2,10 @@
#First cleanup
./CleanAll.sh
+#Cream folderele Object
+mkdir ./protocol/Object
+mkdir ./server/Object
+mkdir ./client/Object
#Creeam protocol
protocolFolder=./protocol/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-19 11:01:21
|
Revision: 44
http://cruce.svn.sourceforge.net/cruce/?rev=44&view=rev
Author: alinposho
Date: 2010-03-19 11:01:09 +0000 (Fri, 19 Mar 2010)
Log Message:
-----------
Am modificat functia unpad(message) - Acum functioneaza.
Mici modificari la server. Acum ajnge pana la faza in care un jucator trebuie sa dea start game.
Modified Paths:
--------------
C/trunk/protocol/protocol.c
C/trunk/server/server.c
Modified: C/trunk/protocol/protocol.c
===================================================================
--- C/trunk/protocol/protocol.c 2010-03-18 18:26:35 UTC (rev 43)
+++ C/trunk/protocol/protocol.c 2010-03-19 11:01:09 UTC (rev 44)
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "protocol.h"
@@ -15,10 +16,9 @@
code = atoi(message);
strcpy(message, message + 2);
}
- printf("Decoded this message:\n");
+ printf("\nDecoded this package:\n");
printf("code: %d\n", code);
- printf("message: %s\n", message);
- printf("---end---\n");
+ printf("message: %s\n\n", message);
return code;
}
@@ -34,8 +34,14 @@
{
int i = strlen(msg) - 1;
for (; i >= 0; i--)
- if (msg[i] != ' ')
+ {
+ if (msg[i] == ' ')
+ {
+ msg[i] = '\0';
+ }
+ else
+ {
break;
-
- msg[i+1] = '\0';
+ }
+ }
}
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-18 18:26:35 UTC (rev 43)
+++ C/trunk/server/server.c 2010-03-19 11:01:09 UTC (rev 44)
@@ -4,7 +4,9 @@
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include "server.h"
#include "../protocol/protocol.h"
@@ -16,6 +18,8 @@
struct sockaddr_in addr;
char ip[16];
+
+
int port;
int sfd;
@@ -33,6 +37,15 @@
}
}
+/**
+ * Prints the message to the output file making sure to flush the buffer
+ */
+void displayInfoMessage(FILE* infoMessageOutput, char *message)
+{
+ fprintf(infoMessageOutput, "%s", message);
+ fflush(infoMessageOutput);
+}
+
/** reads the config file and sets ip and port **/
void readConfig()
{
@@ -48,6 +61,7 @@
perror("Eroare creare socket");
exit(EXIT_FAILURE);
}
+ return s;
}
void bindAndListen()
@@ -202,7 +216,7 @@
switch(code)
{
- case JOIN_GAME:
+ case JOIN_GAME://msg va contine numele jucatorului care a dat join
{
char buffer[200];
sprintf(buffer,"%s joined the game\n",msg);
@@ -216,9 +230,12 @@
{
if(echipe[i].jucatori[j].sfd != fd)
{
- char message[100];
- //sprintf(message, "%s s-a alaturat joucului!\n", jucator.nume);
- sendInfoMessage(echipe[i].jucatori[i].sfd, message);
+ if(echipe[i].jucatori[i].sfd != -1)
+ {
+ char message[100];
+ sprintf(message, "%s s-a alaturat joucului!\n", msg);
+ sendInfoMessage(echipe[i].jucatori[i].sfd, message);
+ }
}
else
echipe[i].jucatori[j].joined = true;
@@ -311,7 +328,7 @@
printf("Message from player %d of team %d ready\n",j,i);
}
if (!bla)
- return; /* daca nu a venit mesaj ies din functie */
+ return 0; /* daca nu a venit mesaj ies din functie */
else
break; /* daca a venit il tratez */
}
@@ -319,21 +336,25 @@
while(1);
/* a venit mesajul de la cine trebe */
- int read_rt;
+ int messageLength;
- read_rt = read(fd,msg,MSG_SIZE);
- printf("Message read. It has %d bytes\n",read_rt);
- if (read_rt == 0)
+ messageLength = read(fd,msg,MSG_SIZE);
+ char infoMSG[1024];
+ sprintf(infoMSG, "Message read. It has %d bytes\n",messageLength);
+ //printf("Message read. It has %d bytes\n",messageLength);
+ displayInfoMessage(stdout, infoMSG);
+
+ if (messageLength == 0)
{
printf("Connection closed\n");
leave_game();
}
- if (read_rt != MSG_SIZE);
+ if (messageLength != MSG_SIZE)
{
displayInfoMessage(stdout, "Warning: too few bytes read\n");
}
- printf("%s\n",msg);
+
//scanf("%*c");
int code = decode_message(msg);
@@ -343,12 +364,8 @@
}
-void displayInfoMessage(FILE* infoMessageOutput, char message[])
-{
- fprintf(infoMessageOutput, "%s", message);
- fflush(infoMessageOutput);
-}
+
int main(int argc, char *argv[])
{
displayInfoMessage(stdout, "Server started!\n");
@@ -378,15 +395,23 @@
getMSG(NULL,ex_msg);
}
- printf("All players are connected\n");
+ sprintf(infoMessage, "All players are connected\n");
+ displayInfoMessage(stdout, infoMessage);
while(!joinGame())
getMSG(NULL,NULL);
- printf("All players have joined\n");
+ sprintf(infoMessage, "All players have joined\n");
+ displayInfoMessage(stdout, infoMessage);
while(!startGame())
getMSG(NULL,NULL);
- printf("Game has started\n");
+ sprintf(infoMessage, "Game has started\n");
+ displayInfoMessage(stdout, infoMessage);
+
+ displayInfoMessage(stdout, "Press any key to close server\n" );
+ getchar();
+
+ return 1;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-22 15:59:41
|
Revision: 47
http://cruce.svn.sourceforge.net/cruce/?rev=47&view=rev
Author: alinposho
Date: 2010-03-22 15:59:34 +0000 (Mon, 22 Mar 2010)
Log Message:
-----------
Property Changed:
----------------
C/trunk/client/
C/trunk/protocol/
C/trunk/server/
Property changes on: C/trunk/client
___________________________________________________________________
Modified: svn:ignore
- client
+ client
Object
Property changes on: C/trunk/protocol
___________________________________________________________________
Added: svn:ignore
+ Object
Property changes on: C/trunk/server
___________________________________________________________________
Modified: svn:ignore
- server
+ server
Object
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-22 17:05:14
|
Revision: 48
http://cruce.svn.sourceforge.net/cruce/?rev=48&view=rev
Author: alinposho
Date: 2010-03-22 17:05:06 +0000 (Mon, 22 Mar 2010)
Log Message:
-----------
Se ajunge cu succes pana in faza de start game. Mai este o mica problema cu afisarea mesajelor la clienti.
Am modificat un pic protocolul adaugand mesajul ALL_PLAYERS_JOINED_GAME care este trimis dupa ce tori au dat join game. Am modificat in player a.i. sa se treaca la faza de start game dupa ce se receptioneaza ALL_PLAYERS_JOINED_GAME.
Modified Paths:
--------------
C/trunk/BuildAll.sh
C/trunk/client/client.c
C/trunk/protocol/protocol.h
C/trunk/server/server.c
Added Paths:
-----------
C/trunk/.settings/
C/trunk/.settings/org.eclipse.cdt.core.prefs
C/trunk/.settings/org.eclipse.cdt.ui.prefs
Added: C/trunk/.settings/org.eclipse.cdt.core.prefs
===================================================================
--- C/trunk/.settings/org.eclipse.cdt.core.prefs (rev 0)
+++ C/trunk/.settings/org.eclipse.cdt.core.prefs 2010-03-22 17:05:06 UTC (rev 48)
@@ -0,0 +1,152 @@
+#Mon Mar 22 18:06:35 EET 2010
+eclipse.preferences.version=1
+org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration=80
+org.eclipse.cdt.core.formatter.alignment_for_compact_if=0
+org.eclipse.cdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.cdt.core.formatter.alignment_for_declarator_list=16
+org.eclipse.cdt.core.formatter.alignment_for_enumerator_list=48
+org.eclipse.cdt.core.formatter.alignment_for_expression_list=0
+org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.cdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.cdt.core.formatter.brace_position_for_array_initializer=next_line
+org.eclipse.cdt.core.formatter.brace_position_for_block=next_line
+org.eclipse.cdt.core.formatter.brace_position_for_block_in_case=next_line
+org.eclipse.cdt.core.formatter.brace_position_for_method_declaration=next_line
+org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration=next_line
+org.eclipse.cdt.core.formatter.brace_position_for_switch=next_line
+org.eclipse.cdt.core.formatter.brace_position_for_type_declaration=next_line
+org.eclipse.cdt.core.formatter.compact_else_if=true
+org.eclipse.cdt.core.formatter.continuation_indentation=2
+org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header=false
+org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier=true
+org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header=false
+org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header=false
+org.eclipse.cdt.core.formatter.indent_empty_lines=false
+org.eclipse.cdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.cdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.cdt.core.formatter.indentation.size=4
+org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration=do not insert
+org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement=insert
+org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert
+org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block=insert
+org.eclipse.cdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.cdt.core.formatter.insert_space_after_binary_operator=insert
+org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_arguments=insert
+org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_parameters=insert
+org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.cdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.cdt.core.formatter.insert_space_after_colon_in_base_clause=insert
+org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.cdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_base_types=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_declarator_list=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_expression_list=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_arguments=insert
+org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_parameters=insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_arguments=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_parameters=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_bracket=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_exception_specification=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.cdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.cdt.core.formatter.insert_space_before_binary_operator=insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_arguments=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_parameters=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_bracket=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_exception_specification=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_colon_in_base_clause=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_declarator_list=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_expression_list=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_arguments=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_parameters=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_arguments=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_parameters=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_bracket=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.cdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.cdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.cdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.cdt.core.formatter.insert_space_between_empty_brackets=do not insert
+org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_exception_specification=do not insert
+org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.cdt.core.formatter.lineSplit=80
+org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.cdt.core.formatter.tabulation.char=tab
+org.eclipse.cdt.core.formatter.tabulation.size=4
+org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations=false
Property changes on: C/trunk/.settings/org.eclipse.cdt.core.prefs
___________________________________________________________________
Added: svn:executable
+ *
Added: C/trunk/.settings/org.eclipse.cdt.ui.prefs
===================================================================
--- C/trunk/.settings/org.eclipse.cdt.ui.prefs (rev 0)
+++ C/trunk/.settings/org.eclipse.cdt.ui.prefs 2010-03-22 17:05:06 UTC (rev 48)
@@ -0,0 +1,4 @@
+#Mon Mar 22 18:06:35 EET 2010
+eclipse.preferences.version=1
+formatter_profile=org.eclipse.cdt.ui.default.allman_profile
+formatter_settings_version=1
Property changes on: C/trunk/.settings/org.eclipse.cdt.ui.prefs
___________________________________________________________________
Added: svn:executable
+ *
Modified: C/trunk/BuildAll.sh
===================================================================
--- C/trunk/BuildAll.sh 2010-03-22 15:59:34 UTC (rev 47)
+++ C/trunk/BuildAll.sh 2010-03-22 17:05:06 UTC (rev 48)
@@ -7,11 +7,15 @@
mkdir ./server/Object
mkdir ./client/Object
+echo
+echo "*********************Starting to build all sources********************************"
+
#Creeam protocol
protocolFolder=./protocol/
protocolMakefile=Makefile
-echo "Building protocol"
+echo
+echo "************Building protocol********************"
cd $protocolFolder
make -f $protocolMakefile
cd ..
@@ -22,7 +26,8 @@
serverFolder=./server/
serverMakefile=Makefile
-echo "Building server"
+echo
+echo "*****************Building server********************"
cd $serverFolder
make -f $serverMakefile
@@ -34,11 +39,14 @@
clientFolder=./client/
clientMakefile=Makefile
-echo "Building client"
+echo
+echo "************************Building client*********************"
cd $clientFolder
make -f $clientMakefile
cd ..
+echo
+echo "***************End Build All ********************************"
+echo
-
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-22 15:59:34 UTC (rev 47)
+++ C/trunk/client/client.c 2010-03-22 17:05:06 UTC (rev 48)
@@ -62,7 +62,17 @@
read(player.sfd, &message, MSG_SIZE);
int code = decode_message(message);
if (code == INFO_MSG)
+ {
printf("%s\n",message);
+ }
+ else
+ {
+ if (ALL_PLAYERS_JOINED_GAME == code)
+ {
+ printf("All players joined the game.\n");
+ return 1;
+ }
+ }
}
return 1;
}
Modified: C/trunk/protocol/protocol.h
===================================================================
--- C/trunk/protocol/protocol.h 2010-03-22 15:59:34 UTC (rev 47)
+++ C/trunk/protocol/protocol.h 2010-03-22 17:05:06 UTC (rev 48)
@@ -22,6 +22,9 @@
#define CARD 14
#define START_ROUND 15
+//propunere extindere protocol
+#define ALL_PLAYERS_JOINED_GAME 16
+
#define DELIMITER " "
int decode_message(char *message);
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-22 15:59:34 UTC (rev 47)
+++ C/trunk/server/server.c 2010-03-22 17:05:06 UTC (rev 48)
@@ -259,20 +259,20 @@
{
for(j = 0; j < JUCATORI_PER_ECHIPA;j++)
{
- struct jucator player = echipe[i].jucatori[j];
- if(player.sfd != fd)
+ struct jucator *player = &(echipe[i].jucatori[j]);
+ if(player->sfd != fd)
{
- if(true != player.joined)
+ if(true == player->joined)
{
char message[100];
sprintf(message, "%s s-a alaturat joucului!\n", msg);
- sendInfoMessage(player.sfd, message);
+ sendInfoMessage(player->sfd, message);
}
}
else
{
- player.joined = true;
- strcpy(player.nume, msg);
+ player->joined = true;
+ strcpy(player->nume, msg);
}
}
}
@@ -298,9 +298,6 @@
sendInfoMessage(player.sfd, resp);
}
}
- //building information message to ohers
-
-
break;
}
default:
@@ -469,7 +466,27 @@
}
}
+//Acesta metoda returneaza 1 in caz de succes si 0 in caz de esec
+int sendMessage(int receiver_sfd, int code, char info[])
+{
+ //adaugam header
+ char buffer[MSG_SIZE];
+ sprintf(buffer, "%d %s", code, info);
+ pad(buffer);
+ //trimitem mesajul pe socket
+ if (write(receiver_sfd, &buffer, MSG_SIZE) != MSG_SIZE)
+ {
+ return false;
+ }
+ else
+ {
+ //succes
+ return true;
+ }
+}
+
+
int main(int argc, char *argv[])
{
displayInfoMessage(stdout, "Server started!\n");
@@ -499,7 +516,7 @@
getMSG(NULL,ex_msg);
}
- sprintf(infoMessage, "All players are connected\n");
+ sprintf(infoMessage, "\n\n****************All players are connected***********************\n\n");
displayInfoMessage(stdout, infoMessage);
int expectedMessages[] = {JOIN_GAME};
@@ -507,7 +524,22 @@
while(!joinGame())
getMSG(NULL,expectedMessages);
- sprintf(infoMessage, "All players have joined\n");
+ int i;
+ int j;
+ //Informam toti jucatorii ca pot incepe jocul
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
+ {
+ if (sendMessage(echipe[i].jucatori[j].sfd, ALL_PLAYERS_JOINED_GAME,
+ "") == false)
+ {
+ displayInfoMessage(stdout,
+ "Eroare la trimiterea mesajului de ALL_PLAYERS_JOINED_GAME\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ sprintf(infoMessage, "\n\n************************All players have joined the game*******************\n");
displayInfoMessage(stdout, infoMessage);
@@ -515,7 +547,7 @@
while(!startGame())
getMSG(NULL,NULL);
- sprintf(infoMessage, "Game has started\n");
+ sprintf(infoMessage, "\n\n*************************Game has started********************\n\n");
displayInfoMessage(stdout, infoMessage);
displayInfoMessage(stdout, "Press any key to close server\n" );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-22 17:48:15
|
Revision: 49
http://cruce.svn.sourceforge.net/cruce/?rev=49&view=rev
Author: alinposho
Date: 2010-03-22 17:48:08 +0000 (Mon, 22 Mar 2010)
Log Message:
-----------
Se ajunge in faza in care toti jucatorii dau start game si astepata sa li se spuna sa inceapa efectiv sa joace. DAR a trebuit sa modific in client.c sa adug mesajul GAME_STARTED si apare mesaje aiurea trimise de server, mesaje pe care le voi leimina imediat. CAius anuntama cand esti la comp si poti lucra la proiect sa nu lucram amandoi la aceeasi chestie.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/protocol/protocol.c
C/trunk/protocol/protocol.h
C/trunk/server/server.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-22 17:05:06 UTC (rev 48)
+++ C/trunk/client/client.c 2010-03-22 17:48:08 UTC (rev 49)
@@ -35,6 +35,7 @@
char answer = 'n';
while (answer != 'y') {
printf("Join game? [y|n]");
+ fflush(stdin);
scanf("%c%*c", &answer);
}
memset(message, 0, MSG_SIZE);
@@ -82,6 +83,7 @@
char answer = 'n';
while (answer != 'y') {
printf("Start game? [y|n]");
+ fflush(stdin);
scanf("%c%*c", &answer);
}
@@ -97,7 +99,8 @@
printf("Received %s from server\n", message);
if (code == NACK)
return 0;
- else if (code == ACK)
+ else
+ if (code == ACK)
return 1;
}
@@ -349,7 +352,38 @@
printf("%s\n", message); // the score for the 2 teams
}
+/**
+ * Asteapta ca toti jucatorii sa dea start game
+ */
+int gameStarted()
+{
+ char message[MSG_SIZE];
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ int code = decode_message(message);
+ if (code == INFO_MSG)
+ {
+ printf("%s\n", message);
+ return 0;
+ }
+ else
+ {
+ if(code == GAME_STARTED)
+ {
+ printf("The game has started!\n");
+ return 1;
+ }
+ else
+ {
+ printf("Received message: %s with code: %d\n", message, code);
+ return 0;
+ }
+ }
+
+}
+
+
/** adresa, port, nume **/
int main(int argc, char *argv[]) {
if (argc != 4) {
@@ -389,6 +423,7 @@
printf("couldn't join the game\n");
exit(1);
}
+
//wait for 4 messages about players
waitAllPlayers();
@@ -398,6 +433,9 @@
exit(1);
}
+ //wait for all player to press start game
+ while(gameStarted() != 1);
+
game();
//shutdown(player.sfd, SHUT_RDWR);
Modified: C/trunk/protocol/protocol.c
===================================================================
--- C/trunk/protocol/protocol.c 2010-03-22 17:05:06 UTC (rev 48)
+++ C/trunk/protocol/protocol.c 2010-03-22 17:48:08 UTC (rev 49)
@@ -5,7 +5,7 @@
#include "protocol.h"
int decode_message(char *message) {
- int code;
+ int code = -1;
unpad(message);
Modified: C/trunk/protocol/protocol.h
===================================================================
--- C/trunk/protocol/protocol.h 2010-03-22 17:05:06 UTC (rev 48)
+++ C/trunk/protocol/protocol.h 2010-03-22 17:48:08 UTC (rev 49)
@@ -24,6 +24,7 @@
//propunere extindere protocol
#define ALL_PLAYERS_JOINED_GAME 16
+#define GAME_STARTED 17
#define DELIMITER " "
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-22 17:05:06 UTC (rev 48)
+++ C/trunk/server/server.c 2010-03-22 17:48:08 UTC (rev 49)
@@ -284,18 +284,18 @@
for(i = 0; i < NUMAR_ECHIPE; i++)
for(j = 0; j < JUCATORI_PER_ECHIPA;j++)
{
- struct jucator player = echipe[i].jucatori[j];
- if(player.sfd == fd)
+ struct jucator *player = &(echipe[i].jucatori[j]);
+ if(player->sfd == fd)
{
char buffer[200];
- sprintf(buffer, "%s wants to start the game\n", player.nume);
+ sprintf(buffer, "%s wants to start the game\n", player->nume);
displayInfoMessage(stdout, buffer);
- player.active = true;
+ player->active = true;
}
else//inform the others who joined the game
{
- sprintf(resp, "%s wants to start the game.\n", msg);
- sendInfoMessage(player.sfd, resp);
+ sprintf(resp, "%d %s wants to start the game.", INFO_MSG, player->nume);
+ sendInfoMessage(player->sfd, resp);
}
}
break;
@@ -519,14 +519,22 @@
sprintf(infoMessage, "\n\n****************All players are connected***********************\n\n");
displayInfoMessage(stdout, infoMessage);
- int expectedMessages[] = {JOIN_GAME};
+ int *expectedMessages;
+ if((expectedMessages = (int *)malloc(sizeof(int))) == NULL)
+ {
+ displayInfoMessage(stdout, "Eroare la alocarea memoriei\n");
+ exit(EXIT_FAILURE);
+ }
+
+ expectedMessages[0] = JOIN_GAME;
+
while(!joinGame())
getMSG(NULL,expectedMessages);
int i;
int j;
- //Informam toti jucatorii ca pot incepe jocul
+ //Informam toti jucatorii ca pot da start game
for (i = 0; i < NUMAR_ECHIPE; i++)
for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
{
@@ -542,11 +550,32 @@
sprintf(infoMessage, "\n\n************************All players have joined the game*******************\n");
displayInfoMessage(stdout, infoMessage);
+ free(expectedMessages);
+ if((expectedMessages = (int *)malloc(sizeof(int))) == NULL)
+ {
+ displayInfoMessage(stdout, "Eroare la alocarea memoriei\n");
+ exit(EXIT_FAILURE);
+ }
+ expectedMessages[0] = START_GAME;
+
while(!startGame())
- getMSG(NULL,NULL);
-
+ getMSG(NULL,expectedMessages);
+
+ //Informam toti jucatorii ca pot incepe jocul
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
+ {
+ if (sendMessage(echipe[i].jucatori[j].sfd, GAME_STARTED,
+ "") == false)
+ {
+ displayInfoMessage(stdout,
+ "Eroare la trimiterea mesajului de ALL_PLAYERS_JOINED_GAME\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
sprintf(infoMessage, "\n\n*************************Game has started********************\n\n");
displayInfoMessage(stdout, infoMessage);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-22 23:07:22
|
Revision: 55
http://cruce.svn.sourceforge.net/cruce/?rev=55&view=rev
Author: alinposho
Date: 2010-03-22 23:07:15 +0000 (Mon, 22 Mar 2010)
Log Message:
-----------
Am adugat functionalitate la playRound, dar nu am tetat-o.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/protocol/protocol.c
C/trunk/server/gameLogic.c
C/trunk/server/server.c
C/trunk/server/server.h
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-22 21:56:17 UTC (rev 54)
+++ C/trunk/client/client.c 2010-03-22 23:07:15 UTC (rev 55)
@@ -54,11 +54,11 @@
return 1;
}
+//asteapta primirea mesajului ALL_PLAYERS_JOINED_GAME
int waitAllPlayers() {
char message[MSG_SIZE];
int i;
- for (i = 3; i > 0; i--) {
- printf("%d more players to join the game...\n", i);
+ for (; ; ) {
memset(message, 0, MSG_SIZE);
read(player.sfd, &message, MSG_SIZE);
int code = decode_message(message);
@@ -97,6 +97,7 @@
unpad(message);
int code = decode_message(message);
printf("Received %s from server\n", message);
+ fflush(stdout);
if (code == NACK)
return 0;
else
@@ -355,29 +356,32 @@
/**
* Asteapta ca toti jucatorii sa dea start game
*/
-int gameStarted()
+void gameStarted()
{
char message[MSG_SIZE];
- memset(message, 0, MSG_SIZE);
- read(player.sfd, &message, MSG_SIZE);
- int code = decode_message(message);
- if (code == INFO_MSG)
+ for (;;)
{
- printf("%s\n", message);
- return 0;
- }
- else
- {
- if(code == GAME_STARTED)
+ memset(message, 0, MSG_SIZE);
+ read(player.sfd, &message, MSG_SIZE);
+ int code = decode_message(message);
+ if (code == INFO_MSG)
{
- printf("The game has started!\n");
- return 1;
+ printf("%s\n", message);
}
else
{
- printf("Received message: %s with code: %d\n", message, code);
- return 0;
+ if (code == GAME_STARTED)
+ {
+ printf("The game has started!\n");
+ fflush(stdout);
+ return;
+ }
+ else
+ {
+ printf("Received message: %s with code: %d\n", message, code);
+ fflush(stdout);
+ }
}
}
@@ -434,7 +438,7 @@
}
//wait for all player to press start game
- while(gameStarted() != 1);
+ gameStarted();
game();
Modified: C/trunk/protocol/protocol.c
===================================================================
--- C/trunk/protocol/protocol.c 2010-03-22 21:56:17 UTC (rev 54)
+++ C/trunk/protocol/protocol.c 2010-03-22 23:07:15 UTC (rev 55)
@@ -44,4 +44,5 @@
break;
}
}
+
}
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-22 21:56:17 UTC (rev 54)
+++ C/trunk/server/gameLogic.c 2010-03-22 23:07:15 UTC (rev 55)
@@ -14,7 +14,7 @@
static void itoa(int n, char a[])
{
- int i, c;
+ int c;
if (n == 0)
{
@@ -35,7 +35,7 @@
//functiacare se ocupa de tot bid-ul de la inceput de joc
//returneaza
-int bid()
+void bid()
{
int i, j;
int expected[] = {BID_RESP,0};
@@ -50,7 +50,13 @@
{
int c_bid;
sendMessage(echipe[i].jucatori[j].sfd,BID,"");
- getMSG(&echipe[i].jucatori[j],expected,bid_ammt,NULL);
+ //Trebuie sa ne asiguram ca mesajul receptionat este bid-ul si nu altceva
+ int code = -1;
+ do
+ {
+ code = getMSG(&echipe[i].jucatori[j],expected,bid_ammt,NULL);
+ }
+ while(code == -1);
c_bid = atoi(bid_ammt);
if (c_bid > maxBid)
{
@@ -60,10 +66,30 @@
handWinnerTeam = i;
}
}
-
- return 0; //TODO ce returnez?
+ //informam jucatorii cine a castigat bid-ul
+ char info[100];
+ sprintf(info, "%s", echipe[handWinnerTeam].jucatori[handWinner].nume);
+ sendMessageToAll(END_BID, info);
+
}
+
+
+
+
+//calculeaza cate puncte a facut echipa in functie de cartile pe care le-a luat
+int puncteFacute(struct echipa team)
+{
+ int i;
+ int valoareCarti = 0;
+ for(i = 0; i < MAX_CARTI; i++)
+ {
+ valoareCarti += team.carti_luate[i].valoare;
+ }
+
+ return valoareCarti / 33;
+}
+
void initCarti(struct carte carti[24])
{
carti[0].valoare = 0;
@@ -139,8 +165,9 @@
carti[23].culoare = 'V';
}
+
//Genereaza si trimite cartile jucatorilor
-int sendCards()
+void sendCards()
{
int r;
int date[24];
@@ -177,14 +204,64 @@
//functia pentru o mana
-int playHand()
+
+void playHand()
{
+ displayInfoMessage(stdout, "Jucam o noua mana!\n");
echipe[0].scor++;
+}
+
+/**
+ * Functia care se ocupa de o runda de joc(de la sendCards pana cand jucatorii nu mai au carti in mana si sunt informati tot de metoda asta
+ * cat a facut fiecare echipa )
+ */
+void playRound()
+{
+ int i;
+ int j;
+
+ displayInfoMessage(stdout, "Jucam o noua runda.\n");
+
+ //fiecare runda incepe cu trimiterea cartilor
+ sendCards();
+
+ bid();
+
+
+ //spunem jcatorului care a castigat bid-ul sa incepa mana
+ for(i = 0; i < CARTI_MANA; i++)
+ {
+ playHand();
+ }
+
+ //Informam jucatorii ca s-a terminat runda si cine cate a facut fiecare echipa
+ char message[MSG_SIZE];
+
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ {
+ int puncte = puncteFacute(echipe[i]);
+ //Verificam daca nu cumva echipa care a castigat bid-ul a facut minus
+ if(i == maxBidTeam)
+ {
+ if(puncte < maxBid)
+ {
+ puncte = -maxBid;
+ }
+
+
+ }
+ sprintf(message, "Ati facut %d", puncte);
+ //trimitem mesajul jucatorilor;
+ for (j = 0; j < MAX_JUCATORI; j++)
+ {
+ sendMessage(echipe[i].jucatori[j].sfd, END_ROUND,message);
+ }
+ }
+
}
-
//Functie care returneaza true cand s-a sfarsit jocul sfarsitul jocului
int endOfGame()
{
@@ -232,8 +309,8 @@
while(false == endOfGame())
{
- displayInfoMessage(stdout, "***\nJucam o noua mana!\n***");
- playHand();
+ displayInfoMessage(stdout, "***\nJucam o noua runda!\n***");
+ playRound();
}
//s-a sfarsit jocul ii informam pe toti
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-22 21:56:17 UTC (rev 54)
+++ C/trunk/server/server.c 2010-03-22 23:07:15 UTC (rev 55)
@@ -252,7 +252,7 @@
sprintf(buffer,"%s joined the game\n",msg);
displayInfoMessage(stdout, buffer);
- sendAckMessage(fd, "You are welcome to connect to server");
+ sendAckMessage(fd, "You are welcome to connect to server.");
//informam restul jucatorilor
for(i = 0; i < NUMAR_ECHIPE; i++)
{
@@ -424,6 +424,7 @@
}
displayInfoMessage(stdout, "Am receptionat mesajul gresit!\n");
+ return -1;
}
static void sigintRoutine(int sigNo)
@@ -496,9 +497,33 @@
}
}
+/**
+ * Functia care trimite un mesaj tuturor jucatorilor
+ * Returneaza 1 in caz de succes si -1 in caz de eroare
+ */
+int sendMessageToAll(int code, char info[])
+{
+ //adaugam header
+ char buffer[MSG_SIZE];
+ sprintf(buffer, "%d %s", code, info);
+ pad(buffer);
+ //trimitem mesajul tuturor jucatorilor
+ int i;
+ int j;
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ for (j = 0; j < MAX_JUCATORI; j++)
+ {
+ if (write(echipe[i].jucatori[j].sfd, &buffer, MSG_SIZE) != MSG_SIZE)
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
int main(int argc, char *argv[])
{
displayInfoMessage(stdout, "Server started!\n");
Modified: C/trunk/server/server.h
===================================================================
--- C/trunk/server/server.h 2010-03-22 21:56:17 UTC (rev 54)
+++ C/trunk/server/server.h 2010-03-22 23:07:15 UTC (rev 55)
@@ -54,7 +54,12 @@
*/
void displayInfoMessage(FILE* infoMessageOutput, char *messag);
-int getMSG(struct jucator *jucator, int *expected, char* restOfMessage, int *sender_sfd);
+int getMSG(struct jucator *jucator, int *expected, char* restOfMessage, int *sender_sfd);
+
+//trimite mesajul jucatorului cu receiver_sfd
int sendMessage(int receiver_sfd, int code, char info[]);
+//trimite mesajul tuturor jucatorilor
+int sendMessageToAll(int code, char info[]);
+
#endif /* __SERVER_H__ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 00:06:31
|
Revision: 56
http://cruce.svn.sourceforge.net/cruce/?rev=56&view=rev
Author: alinposho
Date: 2010-03-23 00:06:24 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
Acum verific functia de create si send cards din server
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/server/gameLogic.c
C/trunk/server/server.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-22 23:07:15 UTC (rev 55)
+++ C/trunk/client/client.c 2010-03-23 00:06:24 UTC (rev 56)
@@ -34,6 +34,7 @@
char message[MSG_SIZE];
char answer = 'n';
while (answer != 'y') {
+ fflush(stdin);
printf("Join game? [y|n]");
fflush(stdin);
scanf("%c%*c", &answer);
@@ -133,7 +134,7 @@
int code = decode_message(message);
if (code != SEND_CARDS)
- return 1;
+ return 0;
int i;
strtok(cardString, " ");
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-22 23:07:15 UTC (rev 55)
+++ C/trunk/server/gameLogic.c 2010-03-23 00:06:24 UTC (rev 56)
@@ -37,6 +37,8 @@
//returneaza
void bid()
{
+ displayInfoMessage(stdout, "\n***Se incepe bid-ul***\n");
+
int i, j;
int expected[] = {BID_RESP,0};
char bid_ammt[2];
@@ -71,6 +73,7 @@
sprintf(info, "%s", echipe[handWinnerTeam].jucatori[handWinner].nume);
sendMessageToAll(END_BID, info);
+ displayInfoMessage(stdout, "\n***S-a terminat bid-ul***\n");
}
@@ -169,6 +172,8 @@
//Genereaza si trimite cartile jucatorilor
void sendCards()
{
+ displayInfoMessage(stdout, "\n***Se impart cartile***\n");
+
int r;
int date[24];
int i, j, k;
@@ -200,14 +205,31 @@
printf("%s\n",string_carti);
sendMessage(echipe[i].jucatori[j].sfd,SEND_CARDS,string_carti);
}
+
+ displayInfoMessage(stdout, "\n***Cartile au fost impartite.***\n");
}
+//initializam toate cartile la valoarea 0 prentu a nu influienta scorul rundei
+void initCartiLuate()
+{
+ int i;
+ int j;
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ {
+ for(j = 0; j < MAX_CARTI; j++)
+ {
+ echipe[i].carti_luate[j].valoare = 0;
+ }
+ }
+}
+
//functia pentru o mana
-
void playHand()
{
- displayInfoMessage(stdout, "Jucam o noua mana!\n");
+
+
+ displayInfoMessage(stdout, "\nJucam o noua mana!\n");
echipe[0].scor++;
}
@@ -220,15 +242,35 @@
{
int i;
int j;
+ int k;
- displayInfoMessage(stdout, "Jucam o noua runda.\n");
+ displayInfoMessage(stdout, "\n***Se incepe o noua runda***\n");
+ //Informam jucatorii ca a inceut o noua runda
+ sendMessageToAll(START_ROUND, "");
+
+ //initializam toate catile luate la 0
+ initCartiLuate();
+
//fiecare runda incepe cu trimiterea cartilor
sendCards();
+ //afisam cartile trimise
+ displayInfoMessage(stdout, "\nCartile trimise sunt:\n");
+ for (i = 0; i < NUMAR_ECHIPE; i++)
+ {
+ printf("Echipa %d\n",i);
+ for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
+ {
+ printf("Jucatorul %d: ",j);
+ for (k = 0; k < CARTI_MANA; k++)
+ printf("[%c %d] ",echipe[i].jucatori[j].carti[k].culoare,echipe[i].jucatori[j].carti[k].valoare);
+ printf("\n");
+ }
+ }
+
bid();
-
//spunem jcatorului care a castigat bid-ul sa incepa mana
for(i = 0; i < CARTI_MANA; i++)
{
@@ -259,6 +301,8 @@
}
}
+ displayInfoMessage(stdout, "\n***S-a sfarsit runda***\n");
+
}
@@ -270,6 +314,7 @@
{
if(echipe[i].scor >= MAX_SCOR)
{
+ displayInfoMessage(stdout, "\n\n*********************S-a terminat jocul*********************\n\n");
return true;
}
}
@@ -286,30 +331,12 @@
void playGame()
{
- int i, j, k;
- printf("Se dau cartile\n");
- sendCards();
-
- printf("Cartile date sunt:\n");
- for (i = 0; i < NUMAR_ECHIPE; i++)
- {
- printf("Echipa %d\n",i);
- for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
- {
- printf("Jucatorul %d: ",j);
- for (k = 0; k < CARTI_MANA; k++)
- printf("[%c %d] ",echipe[i].jucatori[j].carti[k].culoare,echipe[i].jucatori[j].carti[k].valoare);
- printf("\n");
- }
- }
-
-
- bid();
+ displayInfoMessage(stdout, "***Se incepe jocul***\n");
+
while(false == endOfGame())
{
- displayInfoMessage(stdout, "***\nJucam o noua runda!\n***");
playRound();
}
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-22 23:07:15 UTC (rev 55)
+++ C/trunk/server/server.c 2010-03-23 00:06:24 UTC (rev 56)
@@ -162,57 +162,6 @@
exit(EXIT_SUCCESS);
}
-void sendAckMessage(int receiver_sfd, char message[])
-{
- //adaugam header
- char buffer[MSG_SIZE];
- sprintf(buffer, "%d %s", ACK, message);
- pad(buffer);
-
- //trimitem mesajul pe socket
- if(write(receiver_sfd, &message, MSG_SIZE) != MSG_SIZE)
- {
- char buff[MSG_SIZE + 1000];
- sprintf(buff, "Eroare la scrierea mesajului de acknowledge: \n%s\n",message);
- displayInfoMessage(stdout, buff);
- exit(EXIT_FAILURE);
- }
-}
-
-void sendNACKMessage(int receiver_sfd, char message[])
-{
- //adaugam header
- char buffer[MSG_SIZE];
- sprintf(buffer, "%d %s", NACK, message);
- pad(buffer);
-
- //trimitem mesajul pe socket
- if(write(receiver_sfd, &message, MSG_SIZE) != MSG_SIZE)
- {
- char buff[MSG_SIZE + 1000];
- sprintf(buff, "Eroare la scrierea mesajului de acknowledge: \n%s\n",message);
- displayInfoMessage(stdout, buff);
- exit(EXIT_FAILURE);
- }
-}
-
-void sendInfoMessage(int receiver_sfd, char message[])
-{
- //adaugam header
- char buffer[MSG_SIZE];
- sprintf(buffer, "%d %s", INFO_MSG, message);
- pad(buffer);
-
- //trimitem mesajul pe socket
- if(write(receiver_sfd, &message, MSG_SIZE) != MSG_SIZE)
- {
- char buff[MSG_SIZE + 1000];
- sprintf(buff, "Eroare la scrierea mesajului de acknowledge: \n%s\n",message);
- displayInfoMessage(stdout, buff);
- exit(EXIT_FAILURE);
- }
-}
-
/**
* Functia asta returneaza primul file descriptor dintre jucatorii care
* mai sunt conectati la server
@@ -252,7 +201,7 @@
sprintf(buffer,"%s joined the game\n",msg);
displayInfoMessage(stdout, buffer);
- sendAckMessage(fd, "You are welcome to connect to server.");
+ sendMessage(fd, ACK, "You are welcome to connect to server.");
//informam restul jucatorilor
for(i = 0; i < NUMAR_ECHIPE; i++)
{
@@ -265,7 +214,7 @@
{
char message[100];
sprintf(message, "%s s-a alaturat joucului!\n", msg);
- sendInfoMessage(player->sfd, message);
+ sendMessage(player->sfd, INFO_MSG, message);
}
}
else
@@ -290,14 +239,16 @@
sprintf(buffer, "%s wants to start the game\n", player->nume);
displayInfoMessage(stdout, buffer);
player->active = true;
+ //sending ACK
+ sendMessage(player->sfd, ACK, "The game will start in a moment.");
}
else //inform the others who pressed start game
if (true == player->active) //TODO is it neccesary... ca am putea informa pe toti, by default
// sa se simta si sa dea si ei
{
- sprintf(resp, "%d %s wants to start the game.", INFO_MSG,
- player->nume);
- sendInfoMessage(player->sfd, resp);
+ char buff[100];
+ sprintf(buff, "%s wants to start the game too.", player->nume);
+ sendMessage(player->sfd, INFO_MSG, buff);
}
}
break;
@@ -357,7 +308,7 @@
{
//trimitem NACK pentru mesajul ilegal
int fileDescriptor = getFirst_fd_set(set);
- sendNACKMessage(fileDescriptor, "Ai trimis un mesaj ilegal!\n");
+ sendMessage(fileDescriptor, NACK, "Ai trimis un mesaj ilegal!\n");
}
else
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 00:42:16
|
Revision: 58
http://cruce.svn.sourceforge.net/cruce/?rev=58&view=rev
Author: alinposho
Date: 2010-03-23 00:42:10 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
Am rezolvat segmentation fault.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/server/gameLogic.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 00:14:08 UTC (rev 57)
+++ C/trunk/client/client.c 2010-03-23 00:42:10 UTC (rev 58)
@@ -163,12 +163,16 @@
pad(message);
write(player.sfd, &message, MSG_SIZE);
+ printf("\nAm trimis mesajul de acceptare a cartilor server-ului\n");
+
memset(message, 0, MSG_SIZE);
read(player.sfd, &message, MSG_SIZE);
int code = decode_message(message);
if (code == BEGIN_BID)
+ {
return 1;
+ }
return 0;
}
@@ -305,21 +309,31 @@
void round() {
char opt = ' ', ok = 0;
- while (!ok) {
- if (!receiveCards()) {
+ while (!ok)
+ {
+ if (!receiveCards())
+ {
printf("couldn't receive cards\n");
exit(1);
}
- do {
+ do
+ {
showCards();
printf("Do you like your cards? y|n");
- scanf("%c", opt);
+ fflush(stdin);
+ scanf("%c", &opt);
if (opt == 'y')
+ {
ok = accept_cards();
- else if (opt == 'n')
- ok = reject_cards();
- } while(opt != 'y' && opt != 'n');
+ }
+ else
+ {
+ if (opt == 'n')
+ ok = reject_cards();
+ }
+ }
+ while(opt != 'y' && opt != 'n');
}
bidding();
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 00:14:08 UTC (rev 57)
+++ C/trunk/server/gameLogic.c 2010-03-23 00:42:10 UTC (rev 58)
@@ -188,22 +188,58 @@
for (i = 0; i < NUMAR_ECHIPE; i++)
for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
{
- strcpy(string_carti,"");
- for (k = 0; k < CARTI_MANA; k++)
+ int code = -1;
+ do
{
- char valoare[3];
- while(date[(r=(random()%24))]);
- date[r] = 1;
- echipe[i].jucatori[j].carti[k] = carti[r];
- itoa(carti[r].valoare,valoare);
- strcat(string_carti,valoare);
- strcat(string_carti," ");
- string_carti[strlen(string_carti)-1] = carti[r].culoare;
- string_carti[strlen(string_carti)] = '\0';
- strcat(string_carti," ");
- }
- printf("%s\n",string_carti);
- sendMessage(echipe[i].jucatori[j].sfd,SEND_CARDS,string_carti);
+ strcpy(string_carti, "");
+ for (k = 0; k < CARTI_MANA; k++)
+ {
+ char valoare[3];
+ while (date[(r = (random() % 24))])
+ ;
+ date[r] = 1;
+ echipe[i].jucatori[j].carti[k] = carti[r];
+ itoa(carti[r].valoare, valoare);
+ strcat(string_carti, valoare);
+ strcat(string_carti, " ");
+ string_carti[strlen(string_carti) - 1] = carti[r].culoare;
+ string_carti[strlen(string_carti)] = '\0';
+ strcat(string_carti, " ");
+ }
+ printf("%s\n", string_carti);
+ sendMessage(echipe[i].jucatori[j].sfd, SEND_CARDS, string_carti);
+ //verificam daca jucatorul a acceptat cartile trimise
+ int expecttedMessage[] =
+ { ACK, NACK };
+ char info[MSG_SIZE];
+ struct jucator expected_Sender[] = {echipe[i].jucatori[j]};
+ code = getMSG(expected_Sender, expecttedMessage, info,
+ NULL);
+ if (ACK == code)
+ {
+ char buff[100];
+ sprintf(buff, "Jucatorul: %s a acceptat cartile\n",
+ echipe[i].jucatori[j].nume);
+ displayInfoMessage(stdout, buff);
+ }
+ else
+ {
+ if (NACK == code)
+ {
+ char buff[100];
+ sprintf(buff, "Jucatorul: %s NU a acceptat cartile\n",
+ echipe[i].jucatori[j].nume);
+ displayInfoMessage(stdout, buff);
+ //TO DO implemetarea acestei situatii
+ }
+ else
+ {
+ displayInfoMessage(
+ stdout,
+ "Nu s-a recepionat niciun mesaj sau a fost receptionat un mesaj de la cine nu trebuia!\n");
+ }
+ }
+ } while (ACK != code);
}
displayInfoMessage(stdout, "\n***Cartile au fost impartite.***\n");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 01:47:02
|
Revision: 60
http://cruce.svn.sourceforge.net/cruce/?rev=60&view=rev
Author: alinposho
Date: 2010-03-23 01:46:55 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
La client nu ati tratat si cazul in care un jucator ce primeste carti dupa tine, cere refacerea cartilor.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/server/gameLogic.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 01:18:59 UTC (rev 59)
+++ C/trunk/client/client.c 2010-03-23 01:46:55 UTC (rev 60)
@@ -33,8 +33,10 @@
int join_game() {
char message[MSG_SIZE];
char answer = 'n';
- while (answer != 'y') {
+ while (answer != 'y')
+ {
fflush(stdin);
+ fflush(stdout);
printf("Join game? [y|n]");
fflush(stdin);
scanf("%c%*c", &answer);
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 01:18:59 UTC (rev 59)
+++ C/trunk/server/gameLogic.c 2010-03-23 01:46:55 UTC (rev 60)
@@ -168,8 +168,15 @@
carti[23].culoare = 'V';
}
+int checkNACK()
+{
+ return true;
+}
-//Genereaza si trimite cartile jucatorilor
+
+/**
+ * Genereaza si trimite cartile jucatorilor
+ */
void sendCards()
{
displayInfoMessage(stdout, "\n***Se impart cartile***\n");
@@ -185,66 +192,102 @@
srand(1);
memset(date,0,sizeof(int)*24);
- for (i = 0; i < NUMAR_ECHIPE; i++)
- for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
+ int refaCartile;
+
+ do
+ {
+ refaCartile = false;
+
+ for (i = 0; i < NUMAR_ECHIPE; i++)
{
- int code = -1;
- do
+ if(refaCartile == true)
+ break;
+ for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
{
- strcpy(string_carti, "");
- for (k = 0; k < CARTI_MANA; k++)
+ if(refaCartile == true)
+ break;
+ int code = -1;
+ do
{
- char valoare[3];
- while (date[(r = (random() % 24))])
- ;
- date[r] = 1;
- echipe[i].jucatori[j].carti[k] = carti[r];
- itoa(carti[r].valoare, valoare);
- strcat(string_carti, valoare);
- strcat(string_carti, " ");
- string_carti[strlen(string_carti) - 1] = carti[r].culoare;
- string_carti[strlen(string_carti)] = '\0';
- strcat(string_carti, " ");
- }
+ strcpy(string_carti, "");
+ for (k = 0; k < CARTI_MANA; k++)
+ {
+ char valoare[3];
+ while (date[(r = (random() % 24))])
+ ;
+ date[r] = 1;
+ echipe[i].jucatori[j].carti[k] = carti[r];
+ itoa(carti[r].valoare, valoare);
+ strcat(string_carti, valoare);
+ strcat(string_carti, " ");
+ string_carti[strlen(string_carti) - 1]
+ = carti[r].culoare;
+ string_carti[strlen(string_carti)] = '\0';
+ strcat(string_carti, " ");
+ }
- printf("%s\n", string_carti);
- sendMessage(echipe[i].jucatori[j].sfd, SEND_CARDS, string_carti);
- //verificam daca jucatorul a acceptat cartile trimise
- int expecttedMessage[] = { ACK, NACK };
+ printf("%s\n", string_carti);
+ sendMessage(echipe[i].jucatori[j].sfd, SEND_CARDS,
+ string_carti);
- char info[MSG_SIZE];
- struct jucator expected_Sender[] = {echipe[i].jucatori[j]};
+ //verificam daca jucatorul a acceptat cartile trimise
+ int expecttedMessage[] =
+ { ACK, NACK };
- //Asteptam sa receptionam un mesaj OK de la jucatorul tinta
- while((code = getMSG(expected_Sender, expecttedMessage, info, NULL))== -1);
+ char info[MSG_SIZE];
+ struct jucator expected_Sender[] =
+ { echipe[i].jucatori[j] };
- if (ACK == code)
- {
- char buff[100];
- sprintf(buff, "Jucatorul: %s a acceptat cartile\n",
- echipe[i].jucatori[j].nume);
- displayInfoMessage(stdout, buff);
- }
- else
- {
- if (NACK == code)
+ //Asteptam sa receptionam un mesaj OK de la jucatorul tinta
+ while ((code = getMSG(expected_Sender, expecttedMessage,
+ info, NULL)) == -1)
+ ;
+
+ if (ACK == code)
{
char buff[100];
- sprintf(buff, "Jucatorul: %s NU a acceptat cartile\n",
+ sprintf(buff, "Jucatorul: %s a acceptat cartile\n",
echipe[i].jucatori[j].nume);
displayInfoMessage(stdout, buff);
- //TO DO implemetarea acestei situatii adica verificarea refuzului
}
else
{
- displayInfoMessage(
- stdout,
- "Nu s-a recepionat niciun mesaj sau a fost receptionat un mesaj de la cine nu trebuia!\n");
+ if (NACK == code)//se cere refacerea cartilor
+ {
+ char buff[100];
+ sprintf(buff,
+ "Jucatorul: %s NU a acceptat cartile\n",
+ echipe[i].jucatori[j].nume);
+ displayInfoMessage(stdout, buff);
+ //TO DO implemetarea acestei situatii adica verificarea refuzului
+ if (checkNACK() == true)
+ {
+ sendMessage(echipe[i].jucatori[j].sfd, ACK,
+ "S-a acceptat cererea de a reface cartile.");
+ displayInfoMessage(stdout, "S-a acceptat cererea de a reface cartile.\n");
+ refaCartile = true;
+ break;
+ }
+ else
+ {
+ displayInfoMessage(stdout, "NU s-a acceptat cererea de a reface cartile.\n");
+ sendMessage(echipe[i].jucatori[j].sfd, ACK, "Nu s-a acceptat cererea de a reface cartile.");
+ }
+
+ }
+ else
+ {
+ displayInfoMessage(
+ stdout,
+ "Nu s-a recepionat niciun mesaj sau a fost receptionat un mesaj de la cine nu trebuia!\n");
+ }
}
}
+ while (ACK != code);
}
- while (ACK != code);
}
+ }
+ while (refaCartile == true);
displayInfoMessage(stdout, "\n***Cartile au fost impartite.***\n");
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 02:00:38
|
Revision: 61
http://cruce.svn.sourceforge.net/cruce/?rev=61&view=rev
Author: alinposho
Date: 2010-03-23 02:00:32 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
Last commit for this night.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/server/gameLogic.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 01:46:55 UTC (rev 60)
+++ C/trunk/client/client.c 2010-03-23 02:00:32 UTC (rev 61)
@@ -170,6 +170,8 @@
memset(message, 0, MSG_SIZE);
read(player.sfd, &message, MSG_SIZE);
+ printf("\nAsteptam inceputul bid-ului\n");
+
int code = decode_message(message);
if (code == BEGIN_BID)
{
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 01:46:55 UTC (rev 60)
+++ C/trunk/server/gameLogic.c 2010-03-23 02:00:32 UTC (rev 61)
@@ -266,6 +266,10 @@
"S-a acceptat cererea de a reface cartile.");
displayInfoMessage(stdout, "S-a acceptat cererea de a reface cartile.\n");
refaCartile = true;
+
+ sprintf(buff, "Se vor redistribui cartile la cererea lui: %s.", echipe[i].jucatori[j].nume);
+ //informam si ceilalti jucatori de refacerea cartilor
+ sendMessageToAll(INFO_MSG, buff);
break;
}
else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 09:59:20
|
Revision: 66
http://cruce.svn.sourceforge.net/cruce/?rev=66&view=rev
Author: alinposho
Date: 2010-03-23 09:59:14 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
Modificari minore
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/server/gameLogic.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 09:46:23 UTC (rev 65)
+++ C/trunk/client/client.c 2010-03-23 09:59:14 UTC (rev 66)
@@ -290,9 +290,10 @@
void round() {
char opt = ' ', ok = 0;
+ printf("Starting round\n");
+
while (1)
{
- printf("Starting round\n");
char message[MSG_SIZE];
memset(message, 0, MSG_SIZE);
read(player.sfd, &message, MSG_SIZE);
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 09:46:23 UTC (rev 65)
+++ C/trunk/server/gameLogic.c 2010-03-23 09:59:14 UTC (rev 66)
@@ -43,9 +43,7 @@
int expected[] = {BID_RESP,0};
char bid_ammt[2];
- for (i=0; i<NUMAR_ECHIPE; i++)
- for (j=0; j<JUCATORI_PER_ECHIPA; j++)
- sendMessage(echipe[i].jucatori[j].sfd,BEGIN_BID,"");
+ sendMessageToAll(BEGIN_BID, "");
for (i=0; i<NUMAR_ECHIPE; i++)
for (j=0; j<JUCATORI_PER_ECHIPA; j++)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 10:59:27
|
Revision: 68
http://cruce.svn.sourceforge.net/cruce/?rev=68&view=rev
Author: alinposho
Date: 2010-03-23 10:59:21 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
Am testat si modificat logica de bid de la server si totul este OK
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/server/gameLogic.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 10:50:14 UTC (rev 67)
+++ C/trunk/client/client.c 2010-03-23 10:59:21 UTC (rev 68)
@@ -65,10 +65,11 @@
void showCards() {
int i;
- printf("Carti: ");
+ printf("\nCarti: ");
for (i = 0; i < player.carti_ramase; i++)
printf("%s ", player.carti[i].simbol);
printf("\n");
+ fflush(stdout);
}
void deleteCard(int card) {
@@ -234,25 +235,36 @@
int code = decode_message(message);
if (code == INFO_MSG)
+ {
printf("%s\n", message);
+ }
+ else
+ {
+ if (code == BID)
+ {
+ int bid = 0;
+ do
+ {
+ printf("Cate faci? [0, 1, 2, 3, 4, 5, 6]\n");
+ scanf("%d%*c", &bid);
+ }
+ while (bid < 0 || bid > 6);
- else if (code == BID) {
- int bid = 0;
- do {
- printf("Cate faci? [0, 1, 2, 3, 4, 5, 6]\n");
- scanf("%d%*c", &bid);
- } while (bid < 0 || bid > 6);
-
- memset(message, 0, MSG_SIZE);
- sprintf(message, "%d %d", BID_RESP, bid);
- pad(message);
- write(player.sfd, &message, MSG_SIZE);
+ memset(message, 0, MSG_SIZE);
+ sprintf(message, "%d %d", BID_RESP, bid);
+ pad(message);
+ write(player.sfd, &message, MSG_SIZE);
+ }
+ else
+ {
+ if (code == END_BID)
+ {
+ printf("castigator: %s", message);
+ fflush(stdout);
+ ok = 1;
+ }
+ }
}
- else if (code == END_BID) {
- printf("castigator: %s", message);
- ok = 1;
- }
-
}
return 1;
@@ -345,26 +357,32 @@
char message[MSG_SIZE];
memset(message, 0, MSG_SIZE);
read(player.sfd, &message, MSG_SIZE);
- printf("%s\n", message);
unpad(message);
+
char cards[MSG_SIZE];
strcpy(cards, message);
int code = decode_message(message);
- if (code == SEND_CARDS) {
- if (!receiveCards(cards)) {
+ if (code == SEND_CARDS)
+ {
+ if (!receiveCards(cards))
+ {
printf("couldn't receive cards\n");
exit(1);
}
- } else if (code == BEGIN_BID) {
+ }
+ else if (code == BEGIN_BID)
+ {
+ printf("Beginning the bid process!\n");
+ fflush(stdout);
break;
}
do
{
showCards();
- printf("Do you like your cards? y|n");
+ printf("\nDo you like your cards? y|n");
fflush(stdin);
scanf("%c", &opt);
if (opt == 'y')
@@ -376,8 +394,7 @@
if (opt == 'n')
ok = reject_cards();
}
- }
- while(opt != 'y' && opt != 'n');
+ } while (opt != 'y' && opt != 'n');
}
bidding();
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 10:50:14 UTC (rev 67)
+++ C/trunk/server/gameLogic.c 2010-03-23 10:59:21 UTC (rev 68)
@@ -318,7 +318,7 @@
displayInfoMessage(stdout, "\nJucam o noua mana!\n");
- echipe[0].scor++;
+ //echipe[0].scor++;
}
@@ -378,17 +378,33 @@
{
puncte = -maxBid;
}
+ }
+ //Adunam cat a facut echipa runda aceasta la scorul general
+ echipe[i].scor += puncte;
- }
sprintf(message, "Ati facut %d", puncte);
//trimitem mesajul jucatorilor;
- for (j = 0; j < MAX_JUCATORI; j++)
+ for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
{
sendMessage(echipe[i].jucatori[j].sfd, END_ROUND,message);
}
}
+ //Informam toti jucatorii despre starea scorului
+ char buff[200];
+ if(echipe[0].scor > echipe[1].scor)
+ {
+ i = 0;
+ }
+ else
+ {
+ i = 1;
+ }
+
+ sprintf(buff, "Scorul este: %d la %d pentru echipa %s-%s",echipe[i].scor, echipe[i + 1 % 2].scor, echipe[i].jucatori[0].nume, echipe[i].jucatori[1].nume);
+ sendMessageToAll(INFO_MSG, buff);
+
displayInfoMessage(stdout, "\n***S-a sfarsit runda***\n");
}
@@ -419,8 +435,9 @@
void playGame()
{
+ echipe[0].scor = 0;
+ echipe[1].scor = 0;
-
displayInfoMessage(stdout, "***Se incepe jocul***\n");
while(false == endOfGame())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 14:30:27
|
Revision: 70
http://cruce.svn.sourceforge.net/cruce/?rev=70&view=rev
Author: alinposho
Date: 2010-03-23 14:30:20 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
Merge-ul dintre versiunea Upload-ata de aius si versiunea mea.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/server/gameLogic.c
C/trunk/server/server.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 13:14:34 UTC (rev 69)
+++ C/trunk/client/client.c 2010-03-23 14:30:20 UTC (rev 70)
@@ -357,9 +357,7 @@
char message[MSG_SIZE];
memset(message, 0, MSG_SIZE);
read(player.sfd, &message, MSG_SIZE);
- unpad(message);
-
char cards[MSG_SIZE];
strcpy(cards, message);
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 13:14:34 UTC (rev 69)
+++ C/trunk/server/gameLogic.c 2010-03-23 14:30:20 UTC (rev 70)
@@ -236,12 +236,14 @@
//verificam daca jucatorul a acceptat cartile trimise
int expecttedMessage[] =
- { ACK, NACK, 0 };
+ { ACK, NACK };
char info[MSG_SIZE];
+ struct jucator expected_Sender[] =
+ { echipe[i].jucatori[j] };
//Asteptam sa receptionam un mesaj OK de la jucatorul tinta
- while ((code = getMSG(&echipe[i].jucatori[j], expecttedMessage,
+ while ((code = getMSG(expected_Sender, expecttedMessage,
info, NULL)) == -1)
;
@@ -254,14 +256,14 @@
}
else
{
- if (NACK == code) //se cere refacerea cartilor
+ if (NACK == code)//se cere refacerea cartilor
{
char buff[100];
sprintf(buff,
"Jucatorul: %s NU a acceptat cartile\n",
echipe[i].jucatori[j].nume);
displayInfoMessage(stdout, buff);
- // TODO implemetarea acestei situatii adica verificarea refuzului
+ //TO DO implemetarea acestei situatii adica verificarea refuzului
if (checkNACK() == true)
{
sendMessage(echipe[i].jucatori[j].sfd, ACK,
@@ -504,7 +506,9 @@
//spunem jucatorului care a castigat bid-ul sa incepa mana
for(i = 0; i < CARTI_MANA; i++)
+ {
playHand();
+ }
//Informam jucatorii ca s-a terminat runda si cine cate a facut fiecare echipa
char message[MSG_SIZE];
@@ -514,8 +518,12 @@
int puncte = puncteFacute(echipe[i]);
//Verificam daca nu cumva echipa care a castigat bid-ul a facut minus
if(i == maxBidTeam)
+ {
if(puncte < maxBid)
+ {
puncte = -maxBid;
+ }
+ }
//Adunam cat a facut echipa runda aceasta la scorul general
echipe[i].scor += puncte;
@@ -523,15 +531,21 @@
sprintf(message, "Ati facut %d", puncte);
//trimitem mesajul jucatorilor;
for (j = 0; j < JUCATORI_PER_ECHIPA; j++)
- sendMessage(echipe[i].jucatori[j].sfd, END_ROUND, message);
+ {
+ sendMessage(echipe[i].jucatori[j].sfd, END_ROUND,message);
+ }
}
//Informam toti jucatorii despre starea scorului
char buff[200];
if(echipe[0].scor > echipe[1].scor)
+ {
i = 0;
+ }
else
+ {
i = 1;
+ }
sprintf(buff, "Scorul este: %d la %d pentru echipa %s-%s",echipe[i].scor, echipe[i + 1 % 2].scor, echipe[i].jucatori[0].nume, echipe[i].jucatori[1].nume);
sendMessageToAll(INFO_MSG, buff);
@@ -546,11 +560,13 @@
{
int i;
for(i = 0; i < NUMAR_ECHIPE; i++)
+ {
if(echipe[i].scor >= MAX_SCOR)
{
displayInfoMessage(stdout, "\n\n*********************S-a terminat jocul*********************\n\n");
return true;
}
+ }
return false;
}
@@ -570,7 +586,10 @@
displayInfoMessage(stdout, "***Se incepe jocul***\n");
while(false == endOfGame())
+ {
+ //TO DO Rotatia jucatorilor care incep bidul si
playRound();
+ }
//s-a sfarsit jocul ii informam pe toti
inforAllAboutEndOfGame();
Modified: C/trunk/server/server.c
===================================================================
--- C/trunk/server/server.c 2010-03-23 13:14:34 UTC (rev 69)
+++ C/trunk/server/server.c 2010-03-23 14:30:20 UTC (rev 70)
@@ -190,7 +190,6 @@
/** Face ce trebe cu mesajul **/
void dispatchMSG(int code, char *msg, int fd)
{
- char resp[MSG_SIZE];
int i, j;
switch(code)
@@ -267,7 +266,7 @@
/* TODO */
/** Ia un mesaj din retea si vede ce e cu el **/
/* **expected reprezinta un vector de int care specifica ce mesaje se
- * se asteapta sa vina, ultimul element trebuie sa fie 0.
+ * se asteapta sa vina.
* **Jucator este un pointer dar NU este un array. El poate reprezenta un singur jucator daca are valoare sau
* toti jucatorii daca este NULL
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 16:26:28
|
Revision: 72
http://cruce.svn.sourceforge.net/cruce/?rev=72&view=rev
Author: alinposho
Date: 2010-03-23 16:26:21 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
Am adaugat functionalitatea de playHand() la ce facuse Caius anterior. Mai sunt erori, si trebui testat.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/client/client_dummy.c
C/trunk/server/gameLogic.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 15:33:10 UTC (rev 71)
+++ C/trunk/client/client.c 2010-03-23 16:26:21 UTC (rev 72)
@@ -294,6 +294,7 @@
do {
printf("Da carte! (index-ul cartii 0->5)\n");
+ fflush(stdin);
scanf("%d%*c", &card);
} while (card < 0 || card >= player.carti_ramase);
Modified: C/trunk/client/client_dummy.c
===================================================================
--- C/trunk/client/client_dummy.c 2010-03-23 15:33:10 UTC (rev 71)
+++ C/trunk/client/client_dummy.c 2010-03-23 16:26:21 UTC (rev 72)
@@ -224,7 +224,7 @@
else if (code == NACK) // odata cu neacceptarea refuzului jucatorului de a primi cartile, acesta este indreptat spre bid
return 1;
}
-
+//modifying dummy to bid whatever
int bidding() {
char message[MSG_SIZE];
@@ -239,11 +239,12 @@
printf("%s\n", message);
else if (code == BID) {
- int bid = 0;
+ int bid = 3;
+ /*
do {
printf("Cate faci? [0, 1, 2, 3, 4, 5, 6]\n");
scanf("%d%*c", &bid);
- } while (bid < 0 || bid > 6);
+ } while (bid < 0 || bid > 6);*/
memset(message, 0, MSG_SIZE);
sprintf(message, "%d %d", BID_RESP, bid);
@@ -284,7 +285,8 @@
do {
printf("Da carte! (index-ul cartii 0->5)\n");
- scanf("%d%*c", &card);
+ fflush(stdin);
+ scanf("%d", &card);
} while (card < 0 || card >= player.carti_ramase);
memset(message, 0, MSG_SIZE);
@@ -365,9 +367,11 @@
do
{
showCards();
- printf("Do you like your cards? y|n");
- fflush(stdin);
- scanf("%c", &opt);
+ //printf("Do you like your cards? y|n");
+ //fflush(stdin);
+ //scanf("%c", &opt);
+ //modifying dummy to accept ny cards
+ opt = 'y';
if (opt == 'y')
{
ok = accept_cards();
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 15:33:10 UTC (rev 71)
+++ C/trunk/server/gameLogic.c 2010-03-23 16:26:21 UTC (rev 72)
@@ -229,6 +229,7 @@
string_carti[strlen(string_carti)] = '\0';
strcat(string_carti, " ");
}
+ echipe[i].jucatori[j].carti_ramase = 6;
printf("%s\n", string_carti);
sendMessage(echipe[i].jucatori[j].sfd, SEND_CARDS,
@@ -252,6 +253,8 @@
char buff[100];
sprintf(buff, "Jucatorul: %s a acceptat cartile\n",
echipe[i].jucatori[j].nume);
+ //Asociem cartile trimise jucatorului
+
displayInfoMessage(stdout, buff);
}
else
@@ -368,12 +371,9 @@
{
struct carte *carte = NULL;
-
- strtok(cardString, " ");
-
*anunt = 0;
- char *value = strtok(NULL, " ");
+ char *value = strtok(cardString, " ");
char *color = strtok(NULL, " ");
char *a = strtok(NULL, " ");
if (value != NULL && color != NULL)
@@ -389,6 +389,28 @@
}
/**
+ * Sterge o carte din lista de carti a jucatoruilui
+ */
+void deleteCard(struct jucator *jucator, struct carte carteDeSters)
+{
+ int i;
+ for(i=0;i<jucator->carti_ramase;i++)
+ {
+ if(jucator->carti[i].valoare == carteDeSters.valoare && jucator->carti[i].culoare == carteDeSters.culoare)
+ {
+ int j;
+ for(j = i; j < jucator->carti_ramase - 1;j++)
+ jucator->carti[j] = jucator->carti[j + 1];
+ jucator->carti_ramase--;
+ return;
+ }
+ }
+
+ //Somethig is wrong
+ displayInfoMessage(stdout, "Nu am gasit cartea cautata printre cele detinute de jucator!\n");
+}
+
+/**
* Functie care ii cere jucatorului care este la rand sa dea carte.
* Primeste cartea si eventual anuntul, le decodifica si verifica daca s-au respectat regulile.
* iasa din functie doar cand jucatorul a dat cartea care trebuie, iar anutul daca a existat este corect
@@ -427,6 +449,10 @@
cardOK = false;
continue;
}
+ else
+ { //elimina cartea din lista de carti ale jucatorului
+ deleteCard(&echipe[team].jucatori[player], *carte);
+ }
// vad daca am anunt
// TODO verific daca anuntul este corect...
@@ -447,6 +473,7 @@
}
}
}
+ //in cazul in care nu sunt primul pur si simplu se ignora anuntul
carti_luate[order] = *carte;
cardOK = 1;
@@ -500,7 +527,7 @@
int getTotalLuat()
{
int i;
- int t;
+ int t = 0;
for (i=0;i<4;i++)
t += carti_luate[i].valoare;
@@ -518,9 +545,35 @@
// cei 4 jucatori joaca mana
playCard(handWinner,handWinnerTeam,0);
+ //Setam tromful
+ tromf = carti_luate[0].culoare;
+
+ //anuntam ceilalti jucatori care este tromful
+ char buff[100];
+ sprintf(buff, "%s a dat cartea: %d %c care este si tromf.\n",
+ echipe[handWinnerTeam].jucatori[handWinner].nume, carti_luate[0].valoare, carti_luate[0].culoare);
+ sendMessageToAll(INFO_MSG, buff);
+
playCard(handWinner,!handWinnerTeam,1);
+ //anuntam ceilalti jucatori ce carte s-a dat
+ sprintf(buff, "%s a dat cartea: %d %c.\n",
+ echipe[!handWinnerTeam].jucatori[handWinner].nume,
+ carti_luate[1].valoare, carti_luate[1].culoare);
+ sendMessageToAll(INFO_MSG, buff);
+
playCard(!handWinner,handWinnerTeam,2);
+ //anuntam ceilalti jucatori ce carte s-a dat
+ sprintf(buff, "%s a dat cartea: %d %c.\n",
+ echipe[handWinnerTeam].jucatori[!handWinner].nume,
+ carti_luate[2].valoare, carti_luate[2].culoare);
+ sendMessageToAll(INFO_MSG, buff);
+
playCard(!handWinner,!handWinnerTeam,3);
+ //anuntam ceilalti jucatori ce carte s-a dat
+ sprintf(buff, "%s a dat cartea: %d %c.\n",
+ echipe[!handWinnerTeam].jucatori[!handWinner].nume,
+ carti_luate[3].valoare, carti_luate[3].culoare);
+ sendMessageToAll(INFO_MSG, buff);
//Verific cine a luat mana
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ali...@us...> - 2010-03-23 16:42:44
|
Revision: 74
http://cruce.svn.sourceforge.net/cruce/?rev=74&view=rev
Author: alinposho
Date: 2010-03-23 16:42:36 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
In principiu functioneaza logica pentru o mana si o runda, mai trebuie testata partea de final(cand se calculeaza punctele). De asemenea nu am testat logica de anunturi.
Modified Paths:
--------------
C/trunk/client/client.c
C/trunk/client/client_dummy.c
C/trunk/server/gameLogic.c
Modified: C/trunk/client/client.c
===================================================================
--- C/trunk/client/client.c 2010-03-23 16:28:59 UTC (rev 73)
+++ C/trunk/client/client.c 2010-03-23 16:42:36 UTC (rev 74)
@@ -294,7 +294,7 @@
showCards();
do {
- printf("Da carte! (index-ul cartii 0->5)\n");
+ printf("Da carte! (index-ul cartii 0->%d)\n", player.carti_ramase);
fflush(stdin);
scanf("%d%*c", &card);
} while (card < 0 || card >= player.carti_ramase);
@@ -322,7 +322,7 @@
showCards();
do {
- printf("Da carte + anunt daca ai! (index-ul cartii 0->5)\n");
+ printf("Da carte + anunt daca ai! (index-ul cartii 0->%d)\n", player.carti_ramase);
scanf("%d %d%*c", &card, &anunt);
} while (card < 0 || card >= player.carti_ramase);
Modified: C/trunk/client/client_dummy.c
===================================================================
--- C/trunk/client/client_dummy.c 2010-03-23 16:28:59 UTC (rev 73)
+++ C/trunk/client/client_dummy.c 2010-03-23 16:42:36 UTC (rev 74)
@@ -285,7 +285,7 @@
showCards();
do {
- printf("Da carte! (index-ul cartii 0->5)\n");
+ printf("Da carte! (index-ul cartii 0->%d)\n", player.carti_ramase);
fflush(stdin);
scanf("%d", &card);
} while (card < 0 || card >= player.carti_ramase);
@@ -313,7 +313,7 @@
showCards();
do {
- printf("Da carte + anunt daca ai! (index-ul cartii 0->5)\n");
+ printf("Da carte! (index-ul cartii 0->%d)\n", player.carti_ramase);
scanf("%d %d%*c", &card, &anunt);
} while (card < 0 || card >= player.carti_ramase);
Modified: C/trunk/server/gameLogic.c
===================================================================
--- C/trunk/server/gameLogic.c 2010-03-23 16:28:59 UTC (rev 73)
+++ C/trunk/server/gameLogic.c 2010-03-23 16:42:36 UTC (rev 74)
@@ -334,7 +334,7 @@
//verific culoarea
if(carte.culoare != carti_luate[0].culoare)
{
- //verificam daca juatorul are culoare
+ //verificam daca jucatorul are culoare
for(i = 0; i < jucator.carti_ramase;i++)
{
if(jucator.carti[i].culoare == carti_luate[0].culoare)
@@ -550,7 +550,7 @@
//anuntam ceilalti jucatori care este tromful
char buff[100];
- sprintf(buff, "%s a dat cartea: %d %c care este si tromf.\n",
+ sprintf(buff, "%s a dat cartea: %d %c.\n",
echipe[handWinnerTeam].jucatori[handWinner].nume, carti_luate[0].valoare, carti_luate[0].culoare);
sendMessageToAll(INFO_MSG, buff);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|