SQLRETURN SQL_API SQLDataSources(SQLHENV EnvironmentHandle, SQLUSMALLINT Direction, SQLCHAR *ServerName, SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1, SQLCHAR *Description, SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2) { ODBCEnv *env = (ODBCEnv *) EnvironmentHandle; #ifdef ODBCDEBUG ODBCLOG("SQLDataSources " PTRFMT " %s\n", PTRFMTCAST EnvironmentHandle, translateDirection(Direction)); #endif if (!isValidEnv(env)) return SQL_INVALID_HANDLE; clearEnvErrors(env); return MNDBDataSources(env, Direction, ServerName, BufferLength1, NameLength1, Description, BufferLength2, NameLength2); }
SQLRETURN SQL_API SQLDataSourcesW(SQLHENV EnvironmentHandle, SQLUSMALLINT Direction, SQLWCHAR *ServerName, SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1, SQLWCHAR *Description, SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2) { ODBCEnv *env = (ODBCEnv *) EnvironmentHandle; SQLRETURN rc; SQLCHAR *server, *descr; SQLSMALLINT length1, length2; #ifdef ODBCDEBUG ODBCLOG("SQLDataSourcesW " PTRFMT " %s\n", PTRFMTCAST EnvironmentHandle, translateDirection(Direction)); #endif if (!isValidEnv(env)) return SQL_INVALID_HANDLE; clearEnvErrors(env); server = malloc(100); descr = malloc(100); if (server == NULL || descr == NULL) { /* Memory allocation error */ addEnvError(env, "HY001", NULL, 0); if (server) free(server); if (descr) free(descr); return SQL_ERROR; } rc = MNDBDataSources(env, Direction, server, 100, &length1, descr, 100, &length2); if (SQL_SUCCEEDED(rc)) { fixWcharOut(rc, server, length1, ServerName, BufferLength1, NameLength1, 1, addEnvError, env); fixWcharOut(rc, descr, length2, Description, BufferLength2, NameLength2, 1, addEnvError, env); } free(server); free(descr); return rc; }
bool BlockRedstone::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction, int8_t posx, int8_t posy, int8_t posz) { uint8_t block; uint8_t meta; if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta)) { revertBlock(user, x, y, z, map); return true; } /* Check block below allows blocks placed on top */ if (!isBlockStackable(block)) { revertBlock(user, x, y, z, map); return true; } /* move the x,y,z coords dependent upon placement direction */ if (!translateDirection(&x, &y, &z, map, direction)) { revertBlock(user, x, y, z, map); return true; } if (!isBlockEmpty(x, y, z, map)) { revertBlock(user, x, y, z, map); return true; } newblock = 55; meta = 0; ServerInstance->map(map)->setBlock(x, y, z, char(newblock), meta); ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), meta); ServerInstance->redstone(map)->addSimulation(vec(x,y,z)); return false; }
bool BlockRedstoneUtil::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction) { uint8_t block; uint8_t meta = 0; if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta)) { revertBlock(user, x, y, z, map); return true; } /* Check block below allows blocks placed on top */ if (!isBlockStackable(block)) { revertBlock(user, x, y, z, map); return true; } /* move the x,y,z coords dependent upon placement direction */ if (!translateDirection(&x, &y, &z, map, direction)) { revertBlock(user, x, y, z, map); return true; } if (!isBlockEmpty(x, y, z, map)) { revertBlock(user, x, y, z, map); return true; } // Check that switch is placed on legal direction if ((newblock == BLOCK_STONE_BUTTON && (direction == BLOCK_TOP || direction == BLOCK_BOTTOM)) || ((newblock == BLOCK_STONE_PRESSURE_PLATE || newblock == BLOCK_WOODEN_PRESSURE_PLATE) && direction != BLOCK_TOP)) { revertBlock(user, x, y, z, map); return true; } // Set metadata for the position if (newblock == BLOCK_STONE_BUTTON || newblock == BLOCK_LEVER) { // Wall switch if (direction != BLOCK_TOP && direction != BLOCK_BOTTOM) { meta = direction; } // Ceiling lever else if (direction == BLOCK_BOTTOM) { int yaw = abs(int(user->pos.yaw)) % 360; if ((yaw > 45 && yaw <= 135) || (yaw > 225 && yaw <= 315)) { meta = 0x00; } else { meta = 0x07; } } // Floor lever else { int yaw = abs(int(user->pos.yaw)) % 360; if ((yaw > 45 && yaw <= 135) || (yaw > 225 && yaw <= 315)) { meta = 0x06; } else { meta = 0x05; } } } ServerInstance->map(map)->setBlock(x, y, z, char(newblock), meta); ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), meta); return false; }
/* * avatarMake * * Function: Initialize each avatar and send move messages during their respective turns * * Input: @id - current avatar's ID * */ void *avatarMake (void *id){ int avatarID = (intptr_t)id; // Creating ready message AM_Message am_ready; memset(&am_ready, 0, sizeof(AM_Message)); am_ready.type = htonl(AM_AVATAR_READY); am_ready.avatar_ready.AvatarId = htonl(avatarID); // Creting socket for the avatar int sockId; if ((sockId = socket(AF_INET, SOCK_STREAM, 0)) < 0){ fprintf(stderr, "ERROR IN SOCKET 2"); fprintf(logFile, "ERROR IN SOCKET"); exit(1); } // Connect the client to socket if (connect(sockId, (struct sockaddr *) &maze_address, sizeof(maze_address)) < 0) { fprintf(stderr, "There was a problem connecting client to the socket 2\n"); fprintf(logFile, "There was a problem connecting client to the socket\n"); exit(1); } // Sending message to our server send(sockId,&am_ready,sizeof(am_ready),0); // Receiving and checking reply from server AM_Message receiveMessage; if (recv(sockId,&receiveMessage,sizeof(receiveMessage),0) == 0){ fprintf(stderr,"The server connection was closed 2\n"); fprintf(logFile,"The server connection was closed\n"); exit(1); } if (ntohl(receiveMessage.type) != AM_AVATAR_TURN){ fprintf(stderr,"Initialization failed 2"); fprintf(logFile,"Initialization failed"); exit(1); } // initialize avatar position pthread_mutex_lock(&init_mutex); avatarGroup[avatarID]->currpos->x = ntohl(receiveMessage.avatar_turn.Pos[avatarID].x); avatarGroup[avatarID]->currpos->y = ntohl(receiveMessage.avatar_turn.Pos[avatarID].y); avatarGroup[avatarID]->prevpos->x = avatarGroup[avatarID]->currpos->x; avatarGroup[avatarID]->prevpos->y = avatarGroup[avatarID]->currpos->y; pthread_mutex_unlock(&init_mutex); avFlag++; while(avFlag != avatarNum){ sleep(1); } int move; while(1){ // enters only on the avatar's specified turn if(ntohl(receiveMessage.avatar_turn.TurnId) == avatarID){ pthread_mutex_lock(&turn_mutex); totalMoves++; fprintf(logFile,"\nMOVE #%d\n",totalMoves); fprintf(logFile,"avatar %d is at position (%d,%d)\n",avatarID,avatarGroup[avatarID]->currpos->x,avatarGroup[avatarID]->currpos->y); turnID = avatarID; setTarget(); // figure out what move to make (FIX NESW) move = nextMove(avatarID, avatarGroup[avatarID]->currpos,avatarGroup[avatarID]->prevpos); if (move == -1){ fprintf(stderr, "Maze node null\n"); fprintf(logFile,"Maze node null\n"); exit(1); } // print to file saying what move the avatar is trying to make fprintf(logFile,"Avatar %d is trying to move %s \n",avatarID,translateDirection(move)); // Create move message AM_Message moveMessage; memset(&moveMessage,0,sizeof(AM_Message)); moveMessage.type = htonl(AM_AVATAR_MOVE); moveMessage.avatar_move.Direction = htonl(move); moveMessage.avatar_move.AvatarId = htonl(avatarID); // Sending move message send(sockId,&moveMessage,sizeof(moveMessage),0); //receive and check message while (ntohl(receiveMessage.avatar_turn.TurnId) == avatarID){ if (recv(sockId,&receiveMessage,sizeof(receiveMessage),0) == 0){ fprintf(stderr,"The server connection was closed 3\n"); fprintf(logFile,"The server connection was closed\n"); exit(1); } if( totalMoves == (AM_MAX_MOVES*(difficulty+1)*avatarNum)){ if(terminate == 0){ fprintf(stderr,"Exceeded the max number of moves\n"); fprintf(logFile,"\nEXCEEDED THE MAX NUMBER OF MOVES"); terminate = 1; } exit (1); } if(ntohl(receiveMessage.type) == AM_MAZE_SOLVED){ DrawMaze(height, width, avatarGroup, maze, avatarID, avatarNum, filename); if (terminate == 0 ){ printf("solved"); fprintf(logFile,"\nMAZE SOLVED!"); terminate = 1; } return 0; } if(IS_AM_ERROR(ntohl(receiveMessage.type))){ fprintf(stderr,"Error from the server 3"); fprintf(logFile,"Error from the server"); exit(1); } } if (move != M_NULL_MOVE){ XYPos *tmp = (XYPos *)malloc(sizeof(XYPos)); tmp->x = ntohl(receiveMessage.avatar_turn.Pos[avatarID].x); tmp->y = ntohl(receiveMessage.avatar_turn.Pos[avatarID].y); if (avatarMoved(avatarID, avatarGroup[avatarID]->currpos, tmp, move) == 1){ // if the avatar moved, update its previous and current positions avatarGroup[avatarID]->prevpos->x = avatarGroup[avatarID]->currpos->x; avatarGroup[avatarID]->prevpos->y = avatarGroup[avatarID]->currpos->y; avatarGroup[avatarID]->currpos->x = tmp->x; avatarGroup[avatarID]->currpos->y = tmp->y; } free(tmp); } // update the maze graphic DrawMaze(height, width, avatarGroup, maze, avatarID, avatarNum, filename); pthread_mutex_unlock(&turn_mutex); } // when it's not an avatar's turn, it continues to check server messages else{ //receive and check message if (recv(sockId,&receiveMessage,sizeof(receiveMessage),0) == 0){ if(terminate == 0 ){ fprintf(stderr,"The server connection was closed 3\n"); fprintf(logFile,"The server connection was closed\n"); terminate = 1; } exit(1); } if( totalMoves == (AM_MAX_MOVES*(difficulty+1)*avatarNum) ){ if(terminate == 0){ fprintf(stderr,"Exceeded the max number of moves\n"); fprintf(logFile,"\nEXCEEDED MAX NUMBER OF MOVES"); terminate = 1; } exit (1); } if(ntohl(receiveMessage.type) == AM_MAZE_SOLVED){ DrawMaze(height, width, avatarGroup, maze, avatarID, avatarNum, filename); if(terminate == 0){ printf("solved"); fprintf(logFile,"\nMAZE SOLVED!"); terminate = 1; } return 0; } if(IS_AM_ERROR(ntohl(receiveMessage.type))){ if(terminate == 0){ fprintf(stderr,"Error from the server 3"); fprintf(logFile,"Error from the server"); terminate = 1; } exit(1); } } } return 0; }