void Extension::SendBinaryToClient(int Subchannel) { if (Subchannel > 255 || Subchannel < 0) CreateError("Error: Subchannel invalid; it must be between 0 and 255."); else if (!ThreadData.Client) CreateError("Error: Send Binary to Client was called without a Client being selected."); else if (ThreadData.Client->IsClosed) CreateError("Error: Send Binary to Client was called with a closed Client."); else ThreadData.Client->Send(Subchannel, SendMsg, SendMsgSize, 2); if (AutomaticallyClearBinary) ClearBinaryToSend(); }
unsigned int Extension::UnsignedByte(int Index) { if (Index < 0) { CreateError("Could not read from received binary, index less than 0."); return 0; } else if (ThreadData.ReceivedMsg.Size - Index < sizeof(unsigned char)) { CreateError("Could not read from received binary, message is smaller than variable to be read. Check your index."); return 0; } else return (unsigned int)(*(unsigned char *)(ThreadData.ReceivedMsg.Content+Index)); }
void Extension::OnInteractive_ChangePeerName(char * NewName) { if (!NewName || NewName[0] == '\0') CreateError("Cannot change new peer name: Cannot use a null or blank name."); else if (strlen(NewName) > 255) CreateError("Cannot change new peer name: Cannot use a name longer than 255 characters."); else if (InteractivePending == InteractiveType::None) CreateError("Cannot change new peer name: No interactive action is pending."); else if ((InteractivePending & InteractiveType::PeerName) != InteractiveType::PeerName) CreateError("Cannot change new peer name: Interactive event is not compatible with this action."); else if (DenyReason) CreateError("Cannot change new peer name: Name change has already been denied by the Deny Request action."); else NewPeerName = _strdup(NewName); }
void Extension::OnInteractive_ChangeChannelName(char * NewName) { if (!NewName || NewName[0] == '\0') CreateError("Cannot change joining channel name: Cannot use a null or blank name."); else if (strlen(NewName) > 255) CreateError("Cannot change joining channel name: Cannot use a name exceeding the max length of 255 characters."); else if (InteractivePending == InteractiveType::None) CreateError("Cannot change joining channel name: No interactive action is pending."); else if ((InteractivePending & InteractiveType::ChannelName) != InteractiveType::ChannelName) CreateError("Cannot change joining channel name: Interactive event is not compatible with this action."); else if (DenyReason) CreateError("Cannot change joining channel name: Channel name join has already been denied by the Deny Request action."); else NewChannelName = _strdup(NewName); }
float Extension::Float(int Index) { if (Index < 0) { CreateError("Could not read from received binary, index less than 0."); return 0.0f; } else if (ThreadData.ReceivedMsg.Size - Index < sizeof(float)) { CreateError("Could not read from received binary, message is smaller than variable to be read. Check your index."); return 0.0f; } else return (*(float *)(ThreadData.ReceivedMsg.Content + Index)); }
const char * Extension::StrByte(int Index) { if (Index < 0) { CreateError("Could not read from received binary, index less than 0."); return Runtime.CopyString(""); } else if (ThreadData.ReceivedMsg.Size - Index < sizeof(char)) { CreateError("Could not read from received binary, message is smaller than variable to be read. Check your index."); return Runtime.CopyString(""); } else return Runtime.CopyString(std::string(ThreadData.ReceivedMsg.Content+Index, 1).c_str()); }
void Extension::Client_LoopJoinedChannels() { if (!ThreadData.Client) CreateError("Cannot loop client's joined channels: No client selected."); else { SavedExtInfo * Stored = new SaveExtInfo(ThreadData); // Store selected channel and revert after loop Lacewing::RelayServer::Channel * Stored = ThreadData.Channel, *Selected = Srv.FirstChannel(); Lacewing::RelayServer::Client * StoredCli = ThreadData.Client; while (Selected) { while () if (!Selected->IsClosed) { ThreadData.Channel = Selected; ThreadData.Client = StoredCli; Runtime.GenerateEvent(6); } Selected = Selected->Next(); } ThreadData.Channel = Stored; ThreadData.Client = StoredCli; Runtime.GenerateEvent(45); } }
/* Parse a macro */ VyObject ParseMacro(VyParseTree* code){ /* Parse the function arguments */ VyParseTree* args = GetListData(code, 1); int numArguments = 0; char* error = NULL; Argument** arguments = ParseFunctionArguments(args, &numArguments, &error); if(error != NULL){ return ToObject(CreateError(error, code)); } /* Take the rest of the expressions in the lambda as code */ VyParseTree* exprList = MakeListTree(); int i; for(i = 2; i < ListTreeSize(code); i++){ AddToList(exprList, GetListData(code, i)); } /* Take variables from the current function scope and the local scope */ Scope* funcScope = GetCurrentFunctionScope(); Scope* localScope = GetLocalScope(); /* Make sure the local scope isn't the global scope */ if(localScope == GetGlobalScope()) { localScope = NULL; } /* Merge the two scopes to get the current function scope */ Scope* closureScope = MergeScopes(funcScope, localScope); /* Create the function from the data gathered */ VyMacro** mac = CreateMacro(arguments, numArguments, exprList, closureScope); return ToObject(mac); }
void Extension::SetWelcomeMessage(char * Message) { if (!Message) CreateError("SetWelcomeMessage() was called with a null message."); else Srv.SetWelcomeMessage(Message); }
int TCPSocket::Connect(const char *ip, unsigned port) { if (connected || !bound) return -1; NetAddress remote; SecureZeroMemory(&remote, sizeof(remote)); remote.sin_family = AF_INET; remote.sin_port = htons(port); remote.sin_addr.s_addr = inet_addr(ip); int ret = connect(socket, (sockaddr*)&remote, sizeof(remote)); if (ret == SOCKET_ERROR) { if ( !blocking && WSAGetLastError() == WSAEWOULDBLOCK ) { struct timeval time; time.tv_sec = 0; time.tv_usec = 0; //if ( select( 0, socket, socket, NULL, &time ) ) return ret; // would have blocked } Error er = CreateError(Error::E_SocketError); throw er; } connected = true; return 0; }
void Extension::AddString(char * String) { if (String) AddToSend(String, strlen(String) + 1); else CreateError("Adding string failed: pointer was null."); }
void Extension::RelayServer_Host(int port) { if (Srv.Hosting()) CreateError("Cannot start hosting: already hosting a server."); else Srv.Host(port); }
void Extension::AddByteText(char * Byte) { if (!Byte || strnlen(Byte, 2) != 1) CreateError("Adding byte to stack failed: byte supplied was part of a string, not a single byte."); else AddToSend(Byte, 1); }
void Extension::AddStringWithoutNull(char * String) { if (String) AddToSend(String, strlen(String)); else CreateError("Adding string without null failed: pointer was null."); }
void Extension::Client_SelectSender() { if (!ThreadData.SenderClient) CreateError("Cannot select sending client: No sending client variable available."); else ThreadData.Client = ThreadData.SenderClient; }
void Extension::Client_SelectReceiver() { if (!ThreadData.ReceivingClient) CreateError("Cannot select receiving client: No receiving client variable available."); else ThreadData.Client = ThreadData.ReceivingClient; }
// Returns 0 for success, WSAGetLastError() otherwise. int NetAPI_::Init() { if (init) return 0; // initialze winsock int ret = WSAStartup(MAKEWORD(2,2), &wsData); if (ret) { Error er = CreateError(Error::E_NetworkInit); throw er; } // Save local IP address for later convience. localIP = inet_ntoa(*(in_addr*)*gethostbyname("")->h_addr_list); init = true; Config config( "..\\Data\\Config.txt" );\ unsigned low = config.range_.low_; unsigned high = config.range_.high_; while (low <= high) udp_ports.push_back(udp_port(low++,false)); return 0; }
void Extension::Client_LoopJoinedChannelsWithName(char * LoopName) { if (!ThreadData.Client) CreateError("Cannot loop client's joined channels: No client selected."); else { // Store selected channel and revert after loop Lacewing::RelayServer::Channel * Stored = ThreadData.Channel, *Selected = ThreadData.Client->FirstChannel(); Lacewing::RelayServer::Client * StoredCli = ThreadData.Client; while (Selected) { if (!Selected->IsClosed) { ThreadData.Channel = Selected; ThreadData.Client = StoredCli; ThreadData.Loop.Name = LoopName; Runtime.GenerateEvent(36); } Selected = Selected->Next(); } ThreadData.Channel = Stored; ThreadData.Client = StoredCli; ThreadData.Loop.Name = LoopName; Runtime.GenerateEvent(41); ThreadData.Loop.Name = nullptr; } }
void Extension::Client_Disconnect() { if (!ThreadData.Client) CreateError("Could not disconnect client: No client selected."); else if (!ThreadData.Client->IsClosed) ThreadData.Client->Disconnect(); }
void Extension::FlashServer_Host(char * path) { if (FlashSrv.Hosting()) CreateError("Cannot start hosting flash policy: already hosting a flash policy."); else FlashSrv.Host(path); }
int CreateError(int n) { PetscErrorCode ierr; if (!n) SETERRQ(1,"Error Created"); ierr = CreateError(n-1);CHKERRQ(ierr); return 0; }
ICCItem *CCodeChain::CreateParseError (int iLine, const CString &sError) // CreateParseError // // Utility for creating a parse error { return CreateError(strPatternSubst(CONSTLIT("Line %d: %s"), iLine, sError)); }
void Extension::ResizeBinaryToSend(int NewSize) { if (NewSize < 0) CreateError("Cannot change size of binary to send: new size is under 0 bytes."); else { char * NewMsg = (char *)realloc(SendMsg, NewSize); if (!NewMsg) { return CreateError("Cannot change size of binary to send: reallocation of memory failed.\r\n" "Size has not been modified."); } // Clear new bytes to 0 memset(NewMsg + SendMsgSize, 0, NewSize - SendMsgSize); SendMsg = NewMsg; SendMsgSize = NewSize; } }
bool Extension::YouAreChannelMaster() { if (!ThreadData.Channel) { CreateError("Error, You Are Channel Master condition called without valid channel being selected."); return false; } return ThreadData.Channel->IsChannelMaster(); }
int main(int argc,char **argv) { PetscErrorCode ierr; PetscInitialize(&argc,&argv,(char*)0,help); ierr = PetscPrintf(PETSC_COMM_SELF,"This is a contrived example to test floating pointing\n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF,"It is not a true error.\n");CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF,"Run with -fp_trap to catch the floating point error\n");CHKERRQ(ierr); ierr = CreateError(0.0);CHKERRQ(ierr); return 0; }
const char * Extension::CursorStrByte() { if (ThreadData.ReceivedMsg.Size - ThreadData.ReceivedMsg.Cursor < sizeof(char)) { CreateError("Could not read from received binary, message is smaller than variable to be read. Check your index."); return Runtime.CopyString(""); } else return Runtime.CopyString(std::string(ThreadData.ReceivedMsg.Content+ThreadData.ReceivedMsg.Cursor, 1).c_str()); }
const char * Extension::ReceivedStr() { if (ThreadData.ReceivedMsg.Content[ThreadData.ReceivedMsg.Size-1] != '\0') { CreateError("Received$() was used on a message that is not null-terminated."); return Runtime.CopyString(""); } else return Runtime.CopyString(ThreadData.ReceivedMsg.Content); }
int Extension::ReceivedInt() { if (ThreadData.ReceivedMsg.Size != 4) { CreateError("Received() was used on a message that is not a number message."); return 0; } else return *(int *)ThreadData.ReceivedMsg.Content; }
const char * Extension::CursorString() { if (ThreadData.ReceivedMsg.Size - ThreadData.ReceivedMsg.Cursor < 1) { CreateError("Could not read from received binary, message is smaller than variable to be read. Check your index."); return Runtime.CopyString(""); } else if (strnlen(ThreadData.ReceivedMsg.Content + ThreadData.ReceivedMsg.Cursor, ThreadData.ReceivedMsg.Size - ThreadData.ReceivedMsg.Cursor + 1) == ThreadData.ReceivedMsg.Size - ThreadData.ReceivedMsg.Cursor + 1) { CreateError("Could not read null-terminated string; null terminator not found."); return Runtime.CopyString(""); } else { size_t s = ThreadData.ReceivedMsg.Cursor; ThreadData.ReceivedMsg.Cursor += strlen(ThreadData.ReceivedMsg.Content + ThreadData.ReceivedMsg.Cursor)+1; return Runtime.CopyString(ThreadData.ReceivedMsg.Content+s); } }
bool Extension::SelectedPeerIsChannelMaster() { if (!ThreadData.Peer) { CreateError("Error, Selected Peer Is Channel Master condition called without valid peer being selected."); return false; } return ThreadData.Peer->IsChannelMaster(); }